Cataclysm BN
Character Class Referenceabstract

#include <character.h>

Inheritance diagram for Character:
Creature visitable< Character > player avatar npc standard_npc

Classes

struct  comfort_response_t
 
struct  has_mission_item_filter
 
struct  trait_data
 

Public Types

enum class  comfort_level {
  impossible = -999 , uncomfortable = -7 , neutral = 0 , slightly_comfortable = 3 ,
  comfortable = 5 , very_comfortable = 10
}
 
enum  water_tolerance { WT_IGNORED = 0 , WT_NEUTRAL , WT_GOOD , NUM_WATER_TOLERANCE }
 
using trap_map = std::map< tripoint, std::string >
 
- Public Types inherited from Creature
enum  Attitude : int { A_HOSTILE , A_NEUTRAL , A_FRIENDLY , A_ANY }
 Simplified attitude towards any creature: hostile - hate, want to kill, etc. More...
 

Public Member Functions

 Character (const Character &)=delete
 
Characteroperator= (const Character &)=delete
 
 ~Character () override
 
Characteras_character () override
 
const Characteras_character () const override
 
character_id getID () const
 
void setID (character_id i, bool force=false)
 
field_type_id bloodType () const override
 
field_type_id gibType () const override
 
bool is_warm () const override
 
bool in_species (const species_id &spec) const override
 
const std::string & symbol () const override
 
virtual int get_str () const
 Getters for stats exclusive to characters. More...
 
virtual int get_dex () const
 
virtual int get_per () const
 
virtual int get_int () const
 
virtual int get_str_base () const
 
virtual int get_dex_base () const
 
virtual int get_per_base () const
 
virtual int get_int_base () const
 
virtual int get_str_bonus () const
 
virtual int get_dex_bonus () const
 
virtual int get_per_bonus () const
 
virtual int get_int_bonus () const
 
int get_speed () const override
 
virtual int ranged_dex_mod () const
 
virtual int ranged_per_mod () const
 
virtual void set_str_bonus (int nstr)
 Setters for stats exclusive to characters. More...
 
virtual void set_dex_bonus (int ndex)
 
virtual void set_per_bonus (int nper)
 
virtual void set_int_bonus (int nint)
 
virtual void mod_str_bonus (int nstr)
 
virtual void mod_dex_bonus (int ndex)
 
virtual void mod_per_bonus (int nper)
 
virtual void mod_int_bonus (int nint)
 
void print_health () const
 
virtual int get_healthy () const
 Getters for health values exclusive to characters. More...
 
virtual int get_healthy_mod () const
 
virtual void mod_healthy (int nhealthy)
 Modifiers for health values exclusive to characters. More...
 
virtual void mod_healthy_mod (int nhealthy_mod, int cap)
 
virtual void set_healthy (int nhealthy)
 Setters for health values exclusive to characters. More...
 
virtual void set_healthy_mod (int nhealthy_mod)
 
int get_stored_kcal () const
 Getter for need values exclusive to characters. More...
 
int max_stored_kcal () const
 
float get_kcal_percent () const
 
int get_thirst () const
 
std::pair< std::string, nc_colorget_thirst_description () const
 
std::pair< std::string, nc_colorget_hunger_description () const
 
std::pair< std::string, nc_colorget_fatigue_description () const
 
int get_fatigue () const
 
int get_sleep_deprivation () const
 
std::pair< std::string, nc_colorget_pain_description () const override
 
virtual void mod_stored_kcal (int nkcal)
 Modifiers for need values exclusive to characters. More...
 
virtual void mod_stored_nutr (int nnutr)
 
virtual void mod_thirst (int nthirst)
 
virtual void mod_fatigue (int nfatigue)
 
virtual void mod_sleep_deprivation (int nsleep_deprivation)
 
virtual void set_stored_kcal (int kcal)
 Setters for need values exclusive to characters. More...
 
virtual void set_thirst (int nthirst)
 
virtual void set_fatigue (int nfatigue)
 
virtual void set_sleep_deprivation (int nsleep_deprivation)
 
void mod_stat (const std::string &stat, float modifier) override
 
m_size get_size () const override
 Get size class of character. More...
 
void recalculate_size ()
 Recalculate size class of character. More...
 
std::string disp_name (bool possessive=false, bool capitalize_first=false) const override
 Returns either "you" or the player's name. More...
 
std::string skin_name () const override
 Returns the name of the player's outer layer, e.g. More...
 
virtual factionget_faction () const
 
void set_fac_id (const std::string &my_fac_id)
 
int effective_dispersion (int dispersion) const
 
std::vector< aim_typeget_aim_types (const item &gun) const
 
std::pair< int, int > get_fastest_sight (const item &gun, double recoil) const
 
int get_most_accurate_sight (const item &gun) const
 
double aim_speed_skill_modifier (const skill_id &gun_skill) const
 
double aim_speed_dex_modifier () const
 
double aim_speed_encumbrance_modifier () const
 
double aim_cap_from_volume (const item &gun) const
 
double aim_per_move (const item &gun, double recoil) const
 
double recoil_vehicle () const
 Get maximum recoil penalty due to vehicle motion. More...
 
double recoil_mode () const
 
double recoil_total () const
 Current total maximum recoil penalty from all sources. More...
 
float get_dodge_base () const override
 Combat getters. More...
 
float get_hit_base () const override
 
float get_dodge () const override
 
const tripointpos () const override
 
int sight_range (int light_level) const override
 Returns the player's sight range. More...
 
int unimpaired_range () const
 Returns the player maximum vision range factoring in mutations, diseases, and other effects. More...
 
bool overmap_los (const tripoint_abs_omt &omt, int sight_points)
 Returns true if overmap tile is within player line-of-sight. More...
 
int overmap_sight_range (int light_level) const
 Returns the distance the player can see on the overmap. More...
 
int clairvoyance () const
 Returns the distance the player can see through walls. More...
 
bool sight_impaired () const
 Returns true if the player has some form of impaired sight. More...
 
bool has_alarm_clock () const
 Returns true if the player or their vehicle has an alarm clock. More...
 
bool has_watch () const
 Returns true if the player or their vehicle has a watch. More...
 
void action_taken ()
 Called after every action, invalidates player caches. More...
 
bool is_on_ground () const override
 Returns true if the player is knocked over or has broken legs. More...
 
int swim_speed () const
 Returns the player's speed for swimming across water tiles. More...
 
void add_miss_reason (const std::string &reason, unsigned int weight)
 Adds a reason for why the player would miss a melee attack. More...
 
void clear_miss_reasons ()
 Clears the list of reasons for why the player would miss a melee attack. More...
 
std::string get_miss_reason ()
 Returns an explanation for why the player would miss a melee attack. More...
 
void regen (int rate_multiplier)
 Handles passive regeneration of pain and maybe hp. More...
 
void enforce_minimum_healing ()
 
itembest_quality_item (const quality_id &qual)
 get best quality item that this character has More...
 
virtual void update_health (int external_modifiers=0)
 Handles health fluctuations over time. More...
 
void update_body ()
 Updates all "biology" by one turn. More...
 
void update_body (const time_point &from, const time_point &to)
 Updates all "biology" as if time between from and to passed. More...
 
void update_stomach (const time_point &from, const time_point &to)
 Updates the stomach to give accurate hunger messages. More...
 
void update_needs (int rate_multiplier)
 Increases hunger, thirst, fatigue and stimulants wearing off. More...
 
needs_rates calc_needs_rates () const
 
void check_needs_extremes ()
 Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings. More...
 
bool is_hibernating () const
 Returns if the player has hibernation mutation and is asleep and well fed. More...
 
void update_bodytemp (const map &m, const weather_manager &weather)
 Maintains body temperature. More...
 
void temp_equalizer (const bodypart_id &bp1, const bodypart_id &bp2)
 Equalizes heat between body parts. More...
 
comfort_response_t base_comfort_value (const tripoint &p) const
 Rate point's ability to serve as a bed. More...
 
int blood_loss (const bodypart_id &bp) const
 Define blood loss (in percents) More...
 
void reset_bonuses () override
 Resets the value of all bonus fields to 0. More...
 
void reset_stats () override
 Resets stats, and applies effects in an idempotent manner. More...
 
void reset () override
 Handles stat and bonus reset. More...
 
void reset_encumbrance ()
 Recalculates encumbrance cache. More...
 
int encumb (body_part bp) const
 Returns ENC provided by armor, etc. More...
 
units::mass get_weight () const override
 Returns body weight plus weight of inventory and worn/wielded items. More...
 
char_encumbrance_data get_encumbrance () const
 Get encumbrance for all body parts. More...
 
char_encumbrance_data get_encumbrance (const item &new_item) const
 Get encumbrance for all body parts as if new_item was also worn. More...
 
int extraEncumbrance (layer_level level, int bp) const
 Get encumbrance penalty per layer & body part. More...
 
bool is_wearing_power_armor (bool *hasHelmet=nullptr) const
 Returns true if the character is wearing power armor. More...
 
bool is_wearing_active_power_armor () const
 Returns true if the character is wearing active power. More...
 
bool is_wearing_active_optcloak () const
 Returns true if the player is wearing an active optical cloak. More...
 
bool in_climate_control ()
 Returns true if the player is in a climate controlled area or armor. More...
 
bool is_blind () const
 Returns true if the player isn't able to see. More...
 
bool is_invisible () const
 
int visibility (bool check_color=false, int stillness=0) const
 Checks is_invisible() as well as other factors. More...
 
float active_light () const
 Returns character luminosity based on the brightest active item they are carrying. More...
 
bool sees_with_specials (const Creature &critter) const
 
body_part_set exclusive_flag_coverage (const std::string &flag) const
 Bitset of all the body parts covered only with items with flag (or nothing) More...
 
bool move_effects (bool attacking) override
 Processes effects which may prevent the Character from moving (bear traps, crushed, etc.). More...
 
void wait_effects ()
 
bool movement_mode_is (character_movemode mode) const
 Check against the character's current movement mode. More...
 
character_movemode get_movement_mode () const
 
virtual void set_movement_mode (character_movemode mode)=0
 
void expose_to_disease (diseasetype_id dis_type)
 Determine if character is susceptible to dis_type and if so apply the symptoms. More...
 
void process_turn () override
 Handles end-of-turn processing. More...
 
void recalc_hp ()
 Recalculates HP after a change to max strength. More...
 
void calc_all_parts_hp (float hp_mod=0.0, float hp_adjust=0.0, int str_max=0)
 Sets hp for all body parts. More...
 
void recalc_sight_limits ()
 Modifies the player's sight values Must be called when any of the following change: This must be called when any of the following change: More...
 
float get_vision_threshold (float light_level) const
 Returns the apparent light level at which the player can see. More...
 
void flag_encumbrance ()
 Flag encumbrance for updating. More...
 
void check_item_encumbrance_flag ()
 Checks worn items for the "RESET_ENCUMBRANCE" flag, which indicates that encumbrance may have changed and require recalculating. More...
 
bool natural_attack_restricted_on (const bodypart_id &bp) const
 Returns true if the character is wearing something on the entered body_part, ignoring items with the ALLOWS_NATURAL_ATTACKS flag. More...
 
bool can_miss_recovery (const item &weap) const
 Returns true if the player is able to use a miss recovery technique. More...
 
bool is_quiet () const
 Returns true if the player has quiet melee attacks. More...
 
bool block_hit (Creature *source, bodypart_id &bp_hit, damage_instance &dam) override
 Checks for valid block abilities and reduces damage accordingly. More...
 
itembest_shield ()
 Returns the best item for blocking with. More...
 
bool handle_melee_wear (item &shield, float wear_multiplier=1.0f)
 Calculates melee weapon wear-and-tear through use, returns true if item is destroyed. More...
 
matec_id pick_technique (Creature &t, const item &weap, bool crit, bool dodge_counter, bool block_counter)
 Returns a random valid technique. More...
 
void perform_technique (const ma_technique &technique, Creature &t, damage_instance &di, int &move_cost)
 
void melee_attack (Creature &t, bool allow_special, const matec_id &force_technique, bool allow_unarmed=true)
 Sets up a melee attack and handles melee attack function calls. More...
 
void melee_attack (Creature &t, bool allow_special)
 Calls the to other melee_attack function with an empty technique id (meaning no specific technique should be used). More...
 
std::string melee_special_effects (Creature &t, damage_instance &d, item &weap)
 Handles combat effects, returns a string of any valid combat effect messages. More...
 
void perform_special_attacks (Creature &t, dealt_damage_instance &dealt_dam)
 Performs special attacks and their effects (poisonous, stinger, etc.) More...
 
std::vector< special_attackmutation_attacks (Creature &t) const
 Returns a vector of valid mutation attacks. More...
 
float bonus_damage (bool random) const
 Returns the bonus bashing damage the player deals based on their stats. More...
 
float get_melee_hit_base () const
 Returns weapon skill. More...
 
float hit_roll () const override
 Returns the player's basic hit roll that is compared to the target's dodge roll. More...
 
double crit_chance (float roll_hit, float target_dodge, const item &weap) const
 Returns the chance to critical given a hit roll and target's dodge roll. More...
 
bool scored_crit (float target_dodge, const item &weap) const
 Returns true if the player scores a critical hit. More...
 
int attack_cost (const item &weap) const
 Returns cost (in moves) of attacking with given item (no modifiers, like stuck) More...
 
float get_hit_weapon (const item &weap) const
 Gets melee accuracy component from weapon+skills. More...
 
void roll_all_damage (bool crit, damage_instance &di, bool average, const item &weap) const
 Adds all 3 types of physical damage to instance. More...
 
void roll_bash_damage (bool crit, damage_instance &di, bool average, const item &weap) const
 Adds player's total bash damage to the damage instance. More...
 
void roll_cut_damage (bool crit, damage_instance &di, bool average, const item &weap) const
 Adds player's total cut damage to the damage instance. More...
 
void roll_stab_damage (bool crit, damage_instance &di, bool average, const item &weap) const
 Adds player's total stab damage to the damage instance. More...
 
void on_hit (Creature *source, bodypart_id, float, dealt_projectile_attack const *) override
 This creature just got hit by an attack - possibly special/ranged attack - from source. More...
 
void did_hit (Creature &target)
 
void apply_damage (Creature *source, bodypart_id hurt, int dam, bool bypass_med=false) override
 Actually hurt the player, hurts a body_part directly, no armor reduction. More...
 
dealt_damage_instance deal_damage (Creature *source, bodypart_id bp, const damage_instance &d) override
 Calls Creature::deal_damage and handles damaged effects (waking up, etc.) More...
 
int reduce_healing_effect (const efftype_id &eff_id, int remove_med, const bodypart_id &hurt)
 Reduce healing effect intensity, return initial intensity of the effect. More...
 
void cough (bool harmful=false, int loudness=4)
 
void passive_absorb_hit (const bodypart_id &bp, damage_unit &du) const
 Check for relevant passive, non-clothing that can absorb damage, and reduce by specified damage unit. More...
 
void absorb_hit (const bodypart_id &bp, damage_instance &dam) override
 Runs through all bionics and armor on a part and reduces damage through their armor_absorb. More...
 
bool armor_absorb (damage_unit &du, item &armor)
 Reduces and mutates du, prints messages about armor taking damage. More...
 
float bionic_armor_bonus (const bodypart_id &bp, damage_type dt) const
 Check for passive bionics that provide armor, and returns the armor bonus This is called from player::passive_absorb_hit. More...
 
int mabuff_armor_bonus (damage_type type) const
 Returns the armor bonus against given type from martial arts buffs. More...
 
std::map< bodypart_id, int > get_armor_fire (const std::map< bodypart_id, std::vector< const item * > > &clothing_map) const
 Returns overall fire resistance. More...
 
trait_id random_good_trait ()
 Returns the id of a random starting trait that costs >= 0 points. More...
 
trait_id random_bad_trait ()
 Returns the id of a random starting trait that costs < 0 points. More...
 
bool has_trait (const trait_id &b) const override
 Returns true if the player has the entered trait. More...
 
bool has_base_trait (const trait_id &b) const
 Returns true if the player has the entered starting trait. More...
 
bool has_trait_flag (const std::string &b) const
 Returns true if player has a trait with a flag. More...
 
trait_id trait_by_invlet (int ch) const
 Returns the trait id with the given invlet, or an empty string if no trait has that invlet. More...
 
void toggle_trait (const trait_id &)
 Toggles a trait on the player and in their mutation list. More...
 
void set_mutation (const trait_id &)
 Add or removes a mutation on the player, but does not trigger mutation loss/gain effects. More...
 
void unset_mutation (const trait_id &)
 
void switch_mutations (const trait_id &switched, const trait_id &target, bool start_powered)
 Unset switched mutation and set target mutation instead. More...
 
void activate_mutation (const trait_id &mutation)
 
void deactivate_mutation (const trait_id &mut)
 
void mutation_spend_resources (const trait_id &mut)
 Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated mutation). More...
 
bool can_mount (const monster &critter) const
 
void mount_creature (monster &z)
 
bool is_mounted () const
 
bool check_mount_will_move (const tripoint &dest_loc)
 
bool check_mount_is_spooked ()
 
void dismount ()
 
void forced_dismount ()
 
bool is_deaf () const
 
bool has_two_arms () const
 Returns true if the player has two functioning arms. More...
 
int get_working_arm_count () const
 Returns the number of functioning arms. More...
 
int get_working_leg_count () const
 Returns the number of functioning legs. More...
 
bool is_limb_disabled (const bodypart_id &limb) const
 Returns true if the limb is disabled(12.5% or less hp) More...
 
bool is_limb_hindered (hp_part limb) const
 Returns true if the limb is hindered(40% or less hp) More...
 
bool is_limb_broken (const bodypart_id &limb) const
 Returns true if the limb is broken. More...
 
bool can_run ()
 source of truth of whether a Character can run More...
 
void hurtall (int dam, Creature *source, bool disturb=true)
 Hurts all body parts for dam, no armor reduction. More...
 
int hitall (int dam, int vary, Creature *source)
 Harms all body parts for dam, with armor reduction. More...
 
void on_hurt (Creature *source, bool disturb=true)
 Handles effects that happen when the player is damaged and aware of the fact. More...
 
void heal (const bodypart_id &healed, int dam)
 Heals a body_part for dam. More...
 
void healall (int dam)
 Heals all body parts for dam. More...
 
hp_part body_window (const std::string &menu_header, bool show_all, bool precise, int normal_bonus, int head_bonus, int torso_bonus, float bleed, float bite, float infect, float bandage_power, float disinfectant_power) const
 Displays menu with body part hp, optionally with hp estimation after healing. More...
 
nc_color limb_color (const bodypart_id &bp, bool bleed, bool bite, bool infect) const
 
bool made_of (const material_id &m) const override
 
bool made_of_any (const std::set< material_id > &ms) const override
 
int posx () const override
 
int posy () const override
 
int posz () const override
 
void setx (int x)
 
void sety (int y)
 
void setz (int z)
 
void setpos (const tripoint &p) override
 
virtual tripoint global_square_location () const
 Global position, expressed in map square coordinate system (the most detailed coordinate system), used by the map. More...
 
tripoint global_sm_location () const
 Returns the location of the player in global submap coordinates. More...
 
tripoint_abs_omt global_omt_location () const
 Returns the location of the player in global overmap terrain coordinates. More...
 
void recalculate_enchantment_cache ()
 
void rebuild_mutation_cache ()
 
double bonus_from_enchantments (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments for given base value. More...
 
bool has_mabuff (const mabuff_id &buff_id) const
 Returns true if the player has any martial arts buffs attached. More...
 
bool has_grab_break_tec () const override
 Returns true if the player has a grab breaking technique available. More...
 
float mabuff_tohit_bonus () const
 Returns the to hit bonus from martial arts buffs. More...
 
float mabuff_dodge_bonus () const
 Returns the dodge bonus from martial arts buffs. More...
 
int mabuff_block_bonus () const
 Returns the block bonus from martial arts buffs. More...
 
int mabuff_speed_bonus () const
 Returns the speed bonus from martial arts buffs. More...
 
int mabuff_arpen_bonus (damage_type type) const
 Returns the arpen bonus from martial arts buffs. More...
 
float mabuff_damage_mult (damage_type type) const
 Returns the damage multiplier to given type from martial arts buffs. More...
 
int mabuff_damage_bonus (damage_type type) const
 Returns the flat damage bonus to given type from martial arts buffs, applied after the multiplier. More...
 
int mabuff_attack_cost_penalty () const
 Returns the flat penalty to move cost of attacks. More...
 
float mabuff_attack_cost_mult () const
 Returns the multiplier on move cost of attacks. More...
 
void mutation_effect (const trait_id &mut)
 Handles things like removal of armor, etc. More...
 
void mutation_loss_effect (const trait_id &mut)
 Handles what happens when you lose a mutation. More...
 
bool has_active_mutation (const trait_id &b) const
 
void mutate ()
 Picks a random valid mutation and gives it to the Character, possibly removing/changing others along the way. More...
 
bool mutation_ok (const trait_id &mutation, bool force_good, bool force_bad) const
 Returns true if the player doesn't have the mutation or a conflicting one and it complies with the force typing. More...
 
void mutate_category (const std::string &mut_cat)
 Picks a random valid mutation in a category and mutate_towards() it. More...
 
bool mutate_towards (std::vector< trait_id > muts, int num_tries=INT_MAX)
 Mutates toward one of the given mutations, upgrading or removing conflicts if necessary. More...
 
bool mutate_towards (const trait_id &mut)
 Mutates toward the entered mutation, upgrading or removing conflicts if necessary. More...
 
void remove_mutation (const trait_id &mut, bool silent=false)
 Removes a mutation, downgrading to the previous level if possible. More...
 
std::map< trait_id, float > mutation_chances () const
 Calculate percentage chances for mutations. More...
 
bool has_child_flag (const trait_id &flag) const
 Returns true if the player has the entered mutation child flag. More...
 
void remove_child_flag (const trait_id &flag)
 Removes the mutation's child flag from the player's list. More...
 
void set_highest_cat_level ()
 Recalculates mutation_category_level[] values for the player. More...
 
std::string get_highest_category () const
 Returns the highest mutation category. More...
 
void drench_mut_calc ()
 Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats) More...
 
void build_mut_dependency_map (const trait_id &mut, std::unordered_map< trait_id, int > &dependency_map, int distance)
 Recursively traverses the mutation's prerequisites and replacements, building up a map. More...
 
bool is_category_allowed (const std::vector< std::string > &category) const
 Returns true if this category of mutation is allowed. More...
 
bool is_category_allowed (const std::string &category) const
 
bool is_weak_to_water () const
 
bool can_use_heal_item (const item &med) const
 Check for mutation disallowing the use of an healing item. More...
 
bool can_install_cbm_on_bp (const std::vector< bodypart_id > &bps) const
 
resistances mutation_armor (bodypart_id bp) const
 Returns resistances on a body part provided by mutations. More...
 
float mutation_armor (bodypart_id bp, damage_type dt) const
 
float mutation_armor (bodypart_id bp, const damage_unit &du) const
 
bool activate_bionic (int b, bool eff_only=false)
 Handles bionic activation effects of the entered bionic, returns if anything activated. More...
 
std::vector< bionic_idget_bionics () const
 
std::pair< int, int > amount_of_storage_bionics () const
 Returns amount of Storage CBMs in the corpse. More...
 
bool has_bionic (const bionic_id &b) const
 Returns true if the player has the entered bionic id. More...
 
bool has_active_bionic (const bionic_id &b) const
 Returns true if the player has the entered bionic id and it is powered on. More...
 
bool has_any_bionic () const
 Returns true if the player has any bionic. More...
 
bool can_fuel_bionic_with (const item &it) const
 Returns true if the character can fuel a bionic with the item. More...
 
std::vector< bionic_idget_bionic_fueled_with (const item &it) const
 Return bionic_id of bionics able to use it as fuel. More...
 
std::vector< bionic_idget_fueled_bionics () const
 Return bionic_id of fueled bionics. More...
 
bionic_id get_remote_fueled_bionic () const
 Returns bionic_id of first remote fueled bionic found. More...
 
bionic_id get_most_efficient_bionic (const std::vector< bionic_id > &bids) const
 Return bionic_id of bionic of most fuel efficient bionic. More...
 
std::vector< itype_idget_fuel_available (const bionic_id &bio) const
 Return list of available fuel for this bionic. More...
 
int get_fuel_capacity (const itype_id &fuel) const
 Return available space to store specified fuel. More...
 
int get_total_fuel_capacity (const itype_id &fuel) const
 Return total space to store specified fuel. More...
 
void update_fuel_storage (const itype_id &fuel)
 Updates which bionic contain fuel and which is empty. More...
 
int get_mod_stat_from_bionic (const character_stat &Stat) const
 Get stat bonus from bionic. More...
 
void process_bionic (int b)
 Handles bionic effects over time of the entered bionic. More...
 
bool deactivate_bionic (int b, bool eff_only=false)
 Handles bionic deactivation effects of the entered bionic, returns if anything deactivated. More...
 
int num_bionics () const
 Returns the size of my_bionics[]. More...
 
bionicbionic_at_index (int i)
 Returns the bionic at a given index in my_bionics[]. More...
 
void clear_bionics ()
 Remove all bionics. More...
 
int get_used_bionics_slots (const bodypart_id &bp) const
 
int get_total_bionics_slots (const bodypart_id &bp) const
 
int get_free_bionics_slots (const bodypart_id &bp) const
 
bool has_enough_anesth (const itype *cbm, player &patient)
 Has enough anesthetic for surgery. More...
 
void introduce_into_anesthesia (const time_duration &duration, player &installer, bool needs_anesthesia)
 Handles process of introducing patient into anesthesia during Autodoc operations. More...
 
void remove_bionic (const bionic_id &b)
 Removes a bionic from my_bionics[]. More...
 
void add_bionic (const bionic_id &b)
 Adds a bionic to my_bionics[]. More...
 
float env_surgery_bonus (int radius)
 Calculate skill bonus from tiles in radius. More...
 
float bionics_adjusted_skill (const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
 Calculate skill for (un)installing bionics. More...
 
int bionics_pl_skill (const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
 Calculate non adjusted skill for (un)installing bionics. More...
 
bool can_install_bionics (const itype &type, player &installer, bool autodoc=false, int skill_level=-1)
 Is the installation possible. More...
 
std::map< bodypart_id, int > bionic_installation_issues (const bionic_id &bioid) const
 
bool install_bionics (const itype &type, player &installer, bool autodoc=false, int skill_level=-1)
 Initialize all the values needed to start the operation player_activity. More...
 
void perform_install (bionic_id bid, bionic_id upbid, int difficulty, int success, int pl_skill, const std::string &installer_name, const std::vector< trait_id > &trait_to_rem)
 Success or failure of installation happens here. More...
 
void do_damage_for_bionic_failure (int min_damage, int max_damage)
 
void bionics_install_failure (const std::string &installer, int difficulty, int success, float adjusted_skill)
 
bool can_uninstall_bionic (const bionic_id &b_id, player &installer, bool autodoc=false, int skill_level=-1)
 Is The uninstallation possible. More...
 
bool uninstall_bionic (const bionic_id &b_id, player &installer, bool autodoc=false, int skill_level=-1)
 Initialize all the values needed to start the operation player_activity. More...
 
void perform_uninstall (bionic_id bid, int difficulty, int success, const units::energy &power_lvl, int pl_skill)
 Succes or failure of removal happens here. More...
 
void bionics_uninstall_failure (int difficulty, int success, float adjusted_skill)
 When a player fails the surgery. More...
 
bool uninstall_bionic (const bionic &target_cbm, monster &installer, player &patient, float adjusted_skill)
 Used by monster to perform surgery. More...
 
void bionics_uninstall_failure (monster &installer, player &patient, int difficulty, int success, float adjusted_skill)
 When a monster fails the surgery. More...
 
bool burn_fuel (int b, bool start=false)
 Convert fuel to bionic power. More...
 
void passive_power_gen (int b)
 Passively produce power from PERPETUAL fuel. More...
 
itype_id find_remote_fuel (bool look_only=false)
 Find fuel used by remote powered bionic. More...
 
int consume_remote_fuel (int amount)
 Consume fuel used by remote powered bionic, return amount of request unfulfilled (0 if totally successful). More...
 
void reset_remote_fuel ()
 
void heat_emission (int b, int fuel_energy)
 Handle heat from exothermic power generation. More...
 
float get_effective_efficiency (int b, float fuel_efficiency)
 Applies modifier to fuel_efficiency and returns the resulting efficiency. More...
 
units::energy get_power_level () const
 
units::energy get_max_power_level () const
 
void mod_power_level (const units::energy &npower)
 
void mod_max_power_level (const units::energy &npower_max)
 
void set_power_level (const units::energy &npower)
 
void set_max_power_level (const units::energy &npower_max)
 
bool is_max_power () const
 
bool has_power () const
 
bool has_max_power () const
 
bool enough_power_for (const bionic_id &bid) const
 
void conduct_blood_analysis () const
 
bool is_worn (const item &thing) const
 
virtual bool invoke_item (item *, const tripoint &pt)
 Asks how to use the item (if it has more than one use_method) and uses it. More...
 
virtual bool invoke_item (item *, const std::string &, const tripoint &pt)
 As above, but with a pre-selected method. More...
 
virtual bool invoke_item (item *)
 As above two, but with position equal to current position. More...
 
virtual bool invoke_item (item *, const std::string &)
 
virtual bool dispose_item (item_location &&obj, const std::string &prompt=std::string())
 Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves. More...
 
bool has_enough_charges (const item &it, bool show_msg) const
 Has the item enough charges to invoke its use function? Also checks if UPS from this player is used instead of item charges. More...
 
bool consume_charges (item &used, int qty)
 Consume charges of a tool or comestible item, potentially destroying it in the process. More...
 
int item_handling_cost (const item &it, bool penalties=true, int base_cost=INVENTORY_HANDLING_PENALTY) const
 Calculate (but do not deduct) the number of moves required when handling (e.g. More...
 
int item_store_cost (const item &it, const item &container, bool penalties=true, int base_cost=INVENTORY_HANDLING_PENALTY) const
 Calculate (but do not deduct) the number of moves required when storing an item in a container. More...
 
int item_wear_cost (const item &it) const
 Calculate (but do not deduct) the number of moves required to wear an item. More...
 
cata::optional< std::list< item >::iterator > wear_item (const item &to_wear, bool interactive=true)
 Wear item; returns nullopt on fail, or pointer to newly worn item on success. More...
 
int amount_worn (const itype_id &id) const
 Returns the amount of item ‘type’ that is currently worn. More...
 
std::vector< item_locationnearby (const std::function< bool(const item *, const item *)> &func, int radius=1) const
 Returns nearby items which match the provided predicate. More...
 
std::list< itemremove_worn_items_with (std::function< bool(item &)> filter)
 Similar to remove_items_with, but considers only worn items and not their content (item::contents is not checked). More...
 
iteminvlet_to_item (int invlet)
 Return the item pointer of the item with given invlet, return nullptr if the player does not have such an item with that invlet. More...
 
itemi_at (int position)
 
const itemi_at (int position) const
 
int get_item_position (const item *it) const
 Returns the item position (suitable for i_at or similar) of a specific item. More...
 
const itemused_weapon () const
 Returns a reference to the item which will be used to make attacks. More...
 
itemused_weapon ()
 
int i_add_to_container (const item &it, bool unloading)
 Try to find a container/s on character containing ammo of type it.typeId() and add charges until the container is full. More...
 
itemi_add (item it, bool should_stack=true)
 
item i_rem (int pos)
 Remove a specific item from player possession. More...
 
item i_rem (const item *it)
 Remove a specific item from player possession. More...
 
void i_rem_keep_contents (int idx)
 
bool i_add_or_drop (item &it, int qty=1)
 Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded. More...
 
std::bitset< std::numeric_limits< char >::max()> allocated_invlets () const
 Only use for UI things. More...
 
bool has_active_item (const itype_id &id) const
 Whether the player carries an active item of the given item type. More...
 
item remove_weapon ()
 
void remove_mission_items (int mission_id)
 
std::vector< const item * > get_ammo (const ammotype &at) const
 Returns the items that are ammo and have the matching ammo type. More...
 
std::vector< item_locationfind_ammo (const item &obj, bool empty=true, int radius=1) const
 Searches for ammo or magazines that can be used to reload obj. More...
 
std::vector< item_locationfind_reloadables ()
 Searches for weapons and magazines that can be reloaded. More...
 
int ammo_count_for (const item &gun)
 Counts ammo and UPS charges (lower of) for a given gun on the character. More...
 
int throw_range (const item &) const
 Maximum thrown range with a given item, taking all active effects into account. More...
 
bool unarmed_attack () const
 True if unarmed or wielding a weapon with the UNARMED_WEAPON flag. More...
 
int best_nearby_lifting_assist () const
 Checks for items, tools, and vehicles with the Lifting quality near the character returning the highest quality in range. More...
 
int best_nearby_lifting_assist (const tripoint &world_pos) const
 Alternate version if you need to specify a different orign point for nearby vehicle sources of lifting used for operations on distant objects (e.g. More...
 
std::vector< item * > inv_dump ()
 
units::mass weight_carried () const
 
units::volume volume_carried () const
 
units::mass weight_carried_reduced_by (const excluded_stacks &without) const
 
units::volume volume_carried_reduced_by (const excluded_stacks &without) const
 
units::mass weight_capacity () const override
 
units::volume volume_capacity () const
 
units::volume volume_capacity_reduced_by (const units::volume &mod, const excluded_stacks &without={}) const
 
bool can_pick_volume (const item &it) const
 
bool can_pick_volume (units::volume volume) const
 
bool can_pick_weight (const item &it, bool safe=true) const
 
bool can_pick_weight (units::mass weight, bool safe=true) const
 
bool can_use (const item &it, const item &context=item()) const
 Checks if character stats and skills meet minimum requirements for the item. More...
 
ret_val< bool > can_wear (const item &it, bool with_equip_change=false) const
 Check character capable of wearing an item. More...
 
bool is_armed () const
 Returns true if the character is wielding something. More...
 
virtual bool wield (item &target)=0
 Removes currently wielded item (if any) and replaces it with the target item. More...
 
ret_val< bool > can_unwield (const item &it) const
 Check player capable of unwielding an item. More...
 
ret_val< bool > can_swap (const item &it) const
 Check player capable of swapping the side of a worn item. More...
 
void drop_invalid_inventory ()
 
std::list< item * > get_dependent_worn_items (const item &it) const
 Returns all items that must be taken off before taking off this item. More...
 
void drop (item_location loc, const tripoint &where)
 Drops an item to the specified location. More...
 
virtual void drop (const drop_locations &what, const tripoint &target, bool stash=false)
 
virtual bool has_artifact_with (art_effect_passive effect) const
 
bool is_wielding (const item &target) const
 
bool covered_with_flag (const std::string &flag, const body_part_set &parts) const
 
bool is_waterproof (const body_part_set &parts) const
 
int leak_level (const std::string &flag) const
 
bool is_wearing (const item &itm) const
 Returns true if the player is wearing the item. More...
 
bool is_wearing (const itype_id &it) const
 Returns true if the player is wearing an item of this type. More...
 
bool is_wearing_on_bp (const itype_id &it, const bodypart_id &bp) const
 Returns true if the player is wearing the item on the given body part. More...
 
bool worn_with_flag (const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
 Returns true if the player is wearing an item with the given flag. More...
 
const itemitem_worn_with_flag (const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
 Returns the first worn item with a given flag. More...
 
std::vector< std::string > get_overlay_ids () const
 Returns a list of the IDs of overlays on this character, sorted from "lowest" to "highest". More...
 
int get_skill_level (const skill_id &ident) const
 
int get_skill_level (const skill_id &ident, const item &context) const
 
const SkillLevelMapget_all_skills () const
 
SkillLevelget_skill_level_object (const skill_id &ident)
 
const SkillLevelget_skill_level_object (const skill_id &ident) const
 
void set_skill_level (const skill_id &ident, int level)
 
void mod_skill_level (const skill_id &ident, int delta)
 
bool meets_skill_requirements (const std::map< skill_id, int > &req, const item &context=item()) const
 Checks whether the character's skills meet the required. More...
 
bool meets_skill_requirements (const construction &con) const
 Checks whether the character's skills meet the required. More...
 
bool meets_stat_requirements (const item &it) const
 Checks whether the character's stats meets the stats required by the item. More...
 
bool meets_requirements (const item &it, const item &context=item()) const
 Checks whether the character meets overall requirements to be able to use the item. More...
 
std::string enumerate_unmet_requirements (const item &it, const item &context=item()) const
 Returns a string of missed requirements (both stats and skills) More...
 
int rust_rate () const
 Returns the player's skill rust rate. More...
 
int read_speed (bool return_stat_effect=true) const
 Returns the player's reading speed. More...
 
time_point get_time_died () const
 return the calendar::turn the character expired More...
 
void set_time_died (const time_point &time)
 set the turn the turn the character died if not already done More...
 
void normalize () override
 Calls Creature::normalize() nulls out the player's weapon Should only be called through player::normalize(), not on it's own! More...
 
void die (Creature *nkiller) override
 Empty function. More...
 
std::string get_name () const override
 
std::vector< std::string > get_grammatical_genders () const override
 
template<typename ... Args>
bool query_yn (const char *const msg, Args &&... args) const
 It is supposed to hide the query_yn to simplify player vs. More...
 
virtual bool query_yn (const std::string &msg) const =0
 
bool is_immune_field (const field_type_id &fid) const override
 Returns true if we are immune to the field type with the given fid. More...
 
bool is_elec_immune () const override
 Returns true is the player is protected from electric shocks. More...
 
bool is_immune_effect (const efftype_id &) const override
 Returns true if the player is immune to this kind of effect. More...
 
bool is_immune_damage (damage_type) const override
 Returns true if the player is immune to this kind of damage. More...
 
bool is_rad_immune () const
 Returns true if the player is protected from radiation. More...
 
bool is_throw_immune () const
 Returns true if the player is immune to throws. More...
 
bool has_nv ()
 Returns true if the player has some form of night vision. More...
 
float rest_quality () const
 Returns >0 if character is sitting/lying and relatively inactive. More...
 
float healing_rate (float at_rest_quality) const
 Average hit points healed per turn. More...
 
float healing_rate_medicine (float at_rest_quality, const bodypart_id &bp) const
 Average hit points healed per turn from healing effects. More...
 
float mutation_value (const std::string &val) const
 Goes over all mutations, gets min and max of a value with given name. More...
 
social_modifiers get_mutation_social_mods () const
 Goes over all mutations, returning the sum of the social modifiers. More...
 
nc_color symbol_color () const override
 Color's character's tile's background. More...
 
std::string extended_description () const override
 
void empty_skills ()
 
void pick_name (bool bUseDefault=false)
 Returns a random name from NAMES_*. More...
 
std::vector< trait_idget_base_traits () const
 Get the idents of all base traits. More...
 
std::vector< trait_idget_mutations (bool include_hidden=true) const
 Get the idents of all traits/mutations. More...
 
const std::bitset< NUM_VISION_MODES > & get_vision_modes () const
 
void clear_mutations ()
 Empties the trait and mutations lists. More...
 
void add_traits ()
 Adds mandatory scenario and profession traits unless you already have them And if you do already have them, refunds the points for the trait. More...
 
void add_traits (points_left &points)
 
bool crossed_threshold () const
 Returns true if the player has crossed a mutation threshold Player can only cross one mutation threshold. More...
 
void add_addiction (add_type type, int strength)
 Adds an addiction to the player. More...
 
void rem_addiction (add_type type)
 Removes an addition from the player. More...
 
bool has_addiction (add_type type) const
 Returns true if the player has an addiction of the specified type. More...
 
int addiction_level (add_type type) const
 Returns the intensity of the specified addiction. More...
 
void start_hauling ()
 
void stop_hauling ()
 
bool is_hauling () const
 
bool has_item_with_flag (const std::string &flag, bool need_charges=false) const
 
std::vector< const item * > all_items_with_flag (const std::string &flag) const
 All items that have the given flag (item::has_flag). More...
 
bool has_charges (const itype_id &it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >) const
 
std::list< itemuse_amount (itype_id it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >)
 
bool use_charges_if_avail (const itype_id &it, int quantity)
 
std::list< itemuse_charges (const itype_id &what, int qty, const std::function< bool(const item &)> &filter=return_true< item >)
 
bool has_fire (int quantity) const
 
void use_fire (int quantity)
 
void assign_stashed_activity ()
 
bool check_outbounds_activity (const player_activity &act, bool check_only=false)
 
void assign_activity (const activity_id &type, int moves=calendar::INDEFINITELY_LONG, int index=-1, int pos=INT_MIN, const std::string &name="")
 Legacy activity assignment, does not work for any activites using the new activity_actor class and may cause issues with resuming. More...
 
void assign_activity (const player_activity &act, bool allow_resume=true)
 Assigns activity to player, possibly resuming old activity if it's similar enough. More...
 
bool has_activity (const activity_id &type) const
 Check if player currently has a given activity. More...
 
bool has_activity (const std::vector< activity_id > &types) const
 Check if player currently has any of the given activities. More...
 
void resume_backlog_activity ()
 
void cancel_activity ()
 
void cancel_stashed_activity ()
 
player_activity get_stashed_activity () const
 
void set_stashed_activity (const player_activity &act, const player_activity &act_back=player_activity())
 
bool has_stashed_activity () const
 
void initialize_stomach_contents ()
 
float metabolic_rate_base () const
 Stable base metabolic rate due to traits. More...
 
float metabolic_rate () const
 Current metabolic rate due to traits, hunger, speed, etc. More...
 
std::string get_weight_string () const
 
int get_max_healthy () const
 
float bmi () const
 
int bmr () const
 
void reset_chargen_attributes ()
 
int base_age () const
 
void set_base_age (int age)
 
void mod_base_age (int mod)
 
int age () const
 
std::string age_string () const
 
int base_height () const
 
void set_base_height (int height)
 
void mod_base_height (int mod)
 
std::string height_string () const
 
int height () const
 
units::mass bodyweight () const
 
units::mass bionics_weight () const
 
int get_armor_bash (bodypart_id bp) const override
 Returns overall bashing resistance for the body_part. More...
 
int get_armor_cut (bodypart_id bp) const override
 Returns overall cutting resistance for the body_part. More...
 
int get_armor_bullet (bodypart_id bp) const override
 Returns overall bullet resistance for the body_part. More...
 
int get_armor_bash_base (bodypart_id bp) const override
 Returns bashing resistance from the creature and armor only. More...
 
int get_armor_cut_base (bodypart_id bp) const override
 Returns cutting resistance from the creature and armor only. More...
 
int get_armor_bullet_base (bodypart_id bp) const override
 Returns cutting resistance from the creature and armor only. More...
 
int get_env_resist (bodypart_id bp) const override
 Returns overall env_resist on a body_part. More...
 
int get_armor_acid (bodypart_id bp) const
 Returns overall acid resistance for the body part. More...
 
int get_armor_type (damage_type dt, bodypart_id bp) const override
 Returns overall resistance to given type on the bod part. More...
 
std::map< bodypart_id, int > get_all_armor_type (damage_type dt, const std::map< bodypart_id, std::vector< const item * > > &clothing_map) const
 
int get_stim () const
 
void set_stim (int new_stim)
 
void mod_stim (int mod)
 
int get_rad () const
 
void set_rad (int new_rad)
 
void mod_rad (int mod)
 
int get_stamina () const
 
int get_stamina_max () const
 
void set_stamina (int new_stamina)
 
void mod_stamina (int mod)
 
void burn_move_stamina (int moves)
 
float stamina_move_cost_modifier () const
 
void update_stamina (int turns)
 Regenerates stamina. More...
 
void on_item_wear (const item &it)
 Called when an item is worn. More...
 
void on_item_takeoff (const item &it)
 Called when an item is taken off. More...
 
void on_worn_item_washed (const item &it)
 Called when an item is washed. More...
 
void on_effect_int_change (const efftype_id &effect_type, int intensity, const bodypart_str_id &bp) override
 Called when effect intensity has been changed. More...
 
void on_mutation_gain (const trait_id &mid)
 Called when a mutation is gained. More...
 
void on_mutation_loss (const trait_id &mid)
 Called when a mutation is lost. More...
 
void on_stat_change (const std::string &stat, int value) override
 Called when a stat is changed. More...
 
tripoint adjacent_tile () const
 Returns an unoccupied, safe adjacent point. More...
 
bool has_opposite_trait (const trait_id &flag) const
 Returns true if the player has a trait which cancels the entered trait. More...
 
void wake_up ()
 Removes "sleep" and "lying_down". More...
 
int get_shout_volume () const
 
void shout (std::string msg="", bool order=false)
 
void vomit ()
 Handles Character vomiting effects. More...
 
void healed_bp (int bp, int amount)
 
int adjust_for_focus (int amount) const
 
void update_type_of_scent (bool init=false)
 
void update_type_of_scent (const trait_id &mut, bool gain=true)
 
void set_type_of_scent (const scenttype_id &id)
 
scenttype_id get_type_of_scent () const
 
void restore_scent ()
 restore scent after masked_scent effect run out or is removed by water More...
 
void mod_painkiller (int npkill)
 Modifies intensity of painkillers
More...
 
void set_painkiller (int npkill)
 Sets intensity of painkillers
More...
 
int get_painkiller () const
 Returns intensity of painkillers
More...
 
void react_to_felt_pain (int intensity)
 
void spores ()
 
void blossoms ()
 
void rooted_message () const
 Handles rooting effects. More...
 
void rooted ()
 
void fall_asleep ()
 Adds "sleep" to the player. More...
 
void fall_asleep (const time_duration &duration)
 
std::string is_snuggling () const
 Checks to see if the player is using floor items to keep warm, and return the name of one such item if so. More...
 
float power_rating () const override
 Returns an approximation of the creature's strength. More...
 
float speed_rating () const override
 Returns an approximate number of tiles this creature can travel per turn. More...
 
itemitem_with_best_of_quality (const quality_id &qid)
 Returns the item in the player's inventory with the highest of the specified quality. More...
 
bool sees_with_infrared (const Creature &critter) const
 Check whether the this player can see the other creature with infrared. More...
 
void place_corpse ()
 
void place_corpse (const tripoint_abs_omt &om_target)
 
int run_cost (int base_cost, bool diag=false) const
 Returns the player's modified base movement cost. More...
 
const pathfinding_settingsget_pathfinding_settings () const override
 Returns settings for pathfinding. More...
 
std::set< tripointget_path_avoid () const override
 Returns a set of points we do not want to path through. More...
 
std::vector< Creature * > get_hostile_creatures (int range) const
 Get all hostile creatures currently visible to this player. More...
 
std::vector< Creature * > get_visible_creatures (int range) const
 Returns all creatures that this player can see and that are in the given range. More...
 
std::string visible_mutations (int visibility_cap) const
 Returns an enumeration of visible mutations with colors. More...
 
player_activity get_destination_activity () const
 
void set_destination_activity (const player_activity &new_destination_activity)
 
void clear_destination_activity ()
 
std::map< bodypart_id, int > warmth (const std::map< bodypart_id, std::vector< const item * > > &clothing_map) const
 Returns warmth provided by armor, etc. More...
 
bool can_use_floor_warmth () const
 Can the player lie down and cover self with blankets etc. More...
 
int floor_warmth (const tripoint &pos) const
 Final warmth from the floor. More...
 
int bodytemp_modifier_traits (bool overheated) const
 Correction factor of the body temperature due to traits and mutations. More...
 
int bodytemp_modifier_traits_floor () const
 Correction factor of the body temperature due to traits and mutations for player lying on the floor. More...
 
int temp_corrected_by_climate_control (int temperature) const
 Value of the body temperature corrected by climate control. More...
 
bool in_sleep_state () const override
 
void update_vitamins (const vitamin_id &vit)
 Set vitamin deficiency/excess disease states dependent upon current vitamin levels. More...
 
int vitamin_get (const vitamin_id &vit) const
 Check current level of a vitamin. More...
 
bool vitamin_set (const vitamin_id &vit, int qty)
 Sets level of a vitamin or returns false if id given in vit does not exist. More...
 
int vitamin_mod (const vitamin_id &vit, int qty, bool capped=true)
 Add or subtract vitamins from character storage pools. More...
 
void vitamins_mod (const std::map< vitamin_id, int > &, bool capped=true)
 
time_duration vitamin_rate (const vitamin_id &vit) const
 Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects. More...
 
int nutrition_for (const item &comest) const
 Handles the nutrition value for a comestible. More...
 
ret_val< edible_ratingcan_eat (const item &food) const
 Can the food be [theoretically] eaten no matter the consequen ces? More...
 
ret_val< edible_ratingwill_eat (const item &food, bool interactive=false) const
 Same as can_eat, but takes consequences into account. More...
 
bool can_feed_reactor_with (const item &it) const
 Determine character's capability of recharging their CBMs. More...
 
bool can_feed_furnace_with (const item &it) const
 
rechargeable_cbm get_cbm_rechargeable_with (const item &it) const
 
int get_acquirable_energy (const item &it, rechargeable_cbm cbm) const
 
int get_acquirable_energy (const item &it) const
 
bool feed_reactor_with (item &it)
 Recharge CBMs whenever possible. More...
 
bool feed_furnace_with (item &it)
 
bool fuel_bionic_with (item &it)
 
void modify_stimulation (const islot_comestible &comest)
 Used to apply stimulation modifications from food and medication. More...
 
void modify_fatigue (const islot_comestible &comest)
 Used to apply fatigue modifications from food and medication. More...
 
void modify_radiation (const islot_comestible &comest)
 Used to apply radiation from food and medication. More...
 
void modify_addiction (const islot_comestible &comest)
 Used to apply addiction modifications from food and medication. More...
 
void modify_health (const islot_comestible &comest)
 Used to apply health modifications from food and medication. More...
 
bool consume_effects (item &food)
 Handles the effects of consuming an item. More...
 
bool can_consume (const item &it) const
 Check character's capability of consumption overall. More...
 
bool can_estimate_rot () const
 True if the character has enough skill (in cooking or survival) to estimate time to rot. More...
 
bool can_consume_as_is (const item &it) const
 Check whether character can consume this very item. More...
 
bool can_consume_for_bionic (const item &it) const
 
itemget_consumable_from (item &it) const
 Returns a reference to the item itself (if it's consumable), the first of its contents (if it's consumable) or null item otherwise. More...
 
hint_rating rate_action_eat (const item &it) const
 
std::pair< nutrients, nutrientscompute_nutrient_range (const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
 Get calorie & vitamin contents for a comestible, taking into account character traits. More...
 
std::pair< nutrients, nutrientscompute_nutrient_range (const itype_id &, const cata::flat_set< std::string > &extra_flags={}) const
 Same, but across arbitrary recipes. More...
 
morale_type allergy_type (const item &food) const
 Returns allergy type or MORALE_NULL if not allergic for this character. More...
 
nutrients compute_effective_nutrients (const item &) const
 
bool wearing_something_on (const bodypart_id &bp) const
 Returns true if the character is wearing something on the entered body part. More...
 
bool is_wearing_helmet () const
 Returns true if the character is wearing something occupying the helmet slot. More...
 
int head_cloth_encumbrance () const
 Returns the total encumbrance of all SKINTIGHT and HELMET_COMPAT items coveringi the head. More...
 
double armwear_factor () const
 Same as footwear factor, but for arms. More...
 
int shoe_type_count (const itype_id &it) const
 Returns 1 if the player is wearing an item of that count on one foot, 2 if on both, and zero if on neither. More...
 
double footwear_factor () const
 Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither. More...
 
bool is_wearing_shoes (const side &which_side=side::BOTH) const
 Returns true if the player is wearing something on their feet that is not SKINTIGHT. More...
 
bool change_side (item &it, bool interactive=true)
 Swap side on which item is worn; returns false on fail. More...
 
bool change_side (item_location &loc, bool interactive=true)
 
hint_rating rate_action_change_side (const item &it) const
 Used to determine player feedback on item use for the inventory code. More...
 
bool get_check_encumbrance ()
 
void set_check_encumbrance (bool new_check)
 
void update_morale ()
 Ticks down morale counters and removes them. More...
 
void apply_persistent_morale ()
 Ensures persistent morale effects are up-to-date. More...
 
void modify_morale (item &food, int nutr=0)
 Used to apply morale modifications from food and medication. More...
 
int get_morale_level () const
 
void add_morale (const morale_type &type, int bonus, int max_bonus=0, const time_duration &duration=1_hours, const time_duration &decay_start=30_minutes, bool capped=false, const itype *item_type=nullptr)
 
bool has_morale (const morale_type &type) const
 
int get_morale (const morale_type &type) const
 
void rem_morale (const morale_type &type)
 
void clear_morale ()
 
bool has_morale_to_read () const
 
bool has_morale_to_craft () const
 
const inventorycrafting_inventory (bool clear_path)
 
const inventorycrafting_inventory (const tripoint &src_pos=tripoint_zero, int radius=PICKUP_RANGE, bool clear_path=true)
 
void invalidate_crafting_inventory ()
 
bool check_and_recover_morale ()
 Checks permanent morale for consistency and recovers it when an inconsistency is found. More...
 
std::pair< int, int > fun_for (const item &comest) const
 Handles the enjoyability value for a comestible. More...
 
void suffer ()
 Handles a large number of timers decrementing and other randomized effects. More...
 
bool irradiate (float rads, bool bypass=false)
 Handles mitigation and application of radiation. More...
 
void mend (int rate_multiplier)
 Handles the chance for broken limbs to spontaneously heal to 1 HP. More...
 
void sound_hallu ()
 Creates an auditory hallucination. More...
 
void drench (int saturation, const body_part_set &flags, bool ignore_waterproof)
 Drenches the player with water, saturation is the percent gotten wet. More...
 
void apply_wetness_morale (int temperature)
 Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature. More...
 
std::vector< std::string > short_description_parts () const
 
std::string short_description () const
 
int print_info (const catacurses::window &w, int vStart, int vLines, int column) const override
 Write information about this creature. More...
 
bool can_hear (const tripoint &source, int volume) const
 
float hearing_ability () const
 
bool knows_trap (const tripoint &pos) const
 
void add_known_trap (const tripoint &pos, const trap &t)
 
nc_color bodytemp_color (int bp) const
 Define color for displaying the body temperature. More...
 
bool sees (const tripoint &t, bool is_player=false, int range_mod=0) const override
 
bool sees (const Creature &critter) const override
 The functions check whether this creature can see the target. More...
 
Attitude attitude_to (const Creature &other) const override
 Attitude (of this creature) towards another creature. More...
 
int get_lowest_hp () const
 
bool has_weapon () const override
 
void shift_destination (const point &shift)
 
void set_destination (const std::vector< tripoint > &route, const player_activity &new_destination_activity=player_activity())
 
void clear_destination ()
 
bool has_distant_destination () const
 
bool is_auto_moving () const
 
bool has_destination () const
 
bool has_destination_activity () const
 
void start_destination_activity ()
 
std::vector< tripoint > & get_auto_move_route ()
 
action_id get_next_auto_move_direction ()
 
bool defer_move (const tripoint &next)
 
std::map< bodypart_id, float > bodypart_exposure ()
 Map body parts to their total exposure, from 0.0 (fully covered) to 1.0 (buck naked). More...
 
bool pour_into (item &container, item &liquid)
 Try to pour the given liquid into the given container/vehicle. More...
 
bool pour_into (vehicle &veh, item &liquid)
 
- Public Member Functions inherited from Creature
virtual ~Creature ()
 
virtual bool is_player () const
 
virtual bool is_avatar () const
 
virtual bool is_npc () const
 
virtual bool is_monster () const
 
virtual monsteras_monster ()
 
virtual const monsteras_monster () const
 
virtual npcas_npc ()
 
virtual const npcas_npc () const
 
virtual playeras_player ()
 
virtual const playeras_player () const
 
virtual avataras_avatar ()
 
virtual const avataras_avatar () const
 
virtual bool is_fake () const
 Returns true for non-real Creatures used temporarily; i.e. More...
 
virtual void set_fake (bool fake_value)
 Sets a Creature's fake boolean. More...
 
virtual void bleed () const
 Adds an appropriate blood splatter. More...
 
virtual float dodge_roll ()=0
 
virtual float stability_roll () const =0
 
virtual bool avoid_trap (const tripoint &pos, const trap &tr) const =0
 Called when a creature triggers a trap, returns true if they don't set it off. More...
 
Creatureauto_find_hostile_target (int range, int &boo_hoo, int area=0)
 For fake-players (turrets, mounted turrets) this functions chooses a target. More...
 
double ranged_target_size () const
 Size of the target this creature presents to ranged weapons. More...
 
void knock_back_from (const tripoint &p)
 
virtual void knock_back_to (const tripoint &to)=0
 
int size_melee_penalty () const
 
virtual int deal_melee_attack (Creature *source, int hitroll)
 
virtual void deal_melee_hit (Creature *source, int hit_spread, bool critical_hit, const damage_instance &dam, dealt_damage_instance &dealt_dam)
 
virtual void deal_projectile_attack (Creature *source, dealt_projectile_attack &attack)
 Attempts to harm a creature with a projectile. More...
 
virtual void deal_damage_handle_type (const damage_unit &du, bodypart_id bp, int &damage, int &pain)
 
virtual void on_dodge (Creature *source, float difficulty)=0
 This creature just dodged an attack - possibly special/ranged attack - from source. More...
 
virtual bool digging () const
 
virtual bool is_underwater () const
 
virtual bool is_hallucination () const =0
 
virtual bool is_dead_state () const =0
 
bool is_dangerous_fields (const field &fld) const
 Returns true if there is a field in the field set that is dangerous to us. More...
 
bool is_dangerous_field (const field_entry &entry) const
 Returns true if the given field entry is dangerous to us. More...
 
virtual float fall_damage_mod () const =0
 Returns multiplier on fall damage at low velocity (knockback/pit/1 z-level, not 5 z-levels) More...
 
virtual int impact (int force, const tripoint &pos)=0
 Deals falling/collision damage with terrain/creature at pos. More...
 
void check_dead_state ()
 This function checks the creatures is_dead_state and (if true) calls die. More...
 
void add_effect (const effect &eff, bool force=false, bool deferred=false)
 
virtual void add_effect (const efftype_id &eff_id, const time_duration &dur, const bodypart_str_id &bp, int intensity=0, bool force=false, bool deferred=false)
 Adds or modifies an effect. More...
 
void add_effect (const efftype_id &eff_id, const time_duration &dur, body_part bp=num_bp, int intensity=0, bool force=false, bool deferred=false)
 
bool add_env_effect (const efftype_id &eff_id, body_part vector, int strength, const time_duration &dur, body_part bp=num_bp, int intensity=1, bool force=false)
 Gives chance to save via environmental resist, returns false if resistance was successful. More...
 
bool add_env_effect (const efftype_id &eff_id, body_part vector, int strength, const time_duration &dur, body_part bp, bool REMOVED, int intensity=1, bool force=false)=delete
 
bool remove_effect (const efftype_id &eff_id, body_part bp=num_bp)
 Removes a listed effect. More...
 
virtual bool remove_effect (const efftype_id &eff_id, const bodypart_str_id &bp)
 
void clear_effects ()
 Remove all effects. More...
 
bool has_effect (const efftype_id &eff_id, body_part bp=num_bp) const
 Check if creature has the matching effect. More...
 
bool has_effect (const efftype_id &eff_id, const bodypart_str_id &bp) const
 
bool has_effect_with_flag (const std::string &flag, body_part bp=num_bp) const
 Check if creature has any effect with the given flag. More...
 
const effectget_effect (const efftype_id &eff_id, body_part bp=num_bp) const
 Return the effect that matches the given arguments exactly. More...
 
effectget_effect (const efftype_id &eff_id, body_part bp=num_bp)
 
std::vector< const effect * > get_all_effects_of_type (const efftype_id &eff_id) const
 Returns pointers to all effects matching given type. More...
 
time_duration get_effect_dur (const efftype_id &eff_id, body_part bp=num_bp) const
 Returns the duration of the matching effect. More...
 
int get_effect_int (const efftype_id &eff_id, body_part bp=num_bp) const
 Returns the intensity of the matching effect. More...
 
bool resists_effect (const effect &e) const
 Returns true if the creature resists an effect. More...
 
void set_value (const std::string &key, const std::string &value)
 
void remove_value (const std::string &key)
 
std::string get_value (const std::string &key) const
 
void process_effects ()
 Processes through all the effects on the Creature. More...
 
virtual void process_effects_internal ()=0
 Processes effects according to class (monster, player) More...
 
virtual void mod_pain (int npain)
 
virtual void mod_pain_noresist (int npain)
 
virtual void set_pain (int npain)
 
virtual int get_pain () const
 
virtual int get_perceived_pain () const
 
int get_moves () const
 
void mod_moves (int nmoves)
 
void set_moves (int nmoves)
 
virtual Creatureget_killer () const
 
virtual int get_num_blocks () const
 
virtual int get_num_dodges () const
 
virtual int get_num_blocks_bonus () const
 
virtual int get_num_dodges_bonus () const
 
virtual int get_num_dodges_base () const
 
virtual int get_armor_bash_bonus () const
 
virtual int get_armor_cut_bonus () const
 
virtual int get_armor_bullet_bonus () const
 
virtual float get_melee () const =0
 
virtual float get_hit () const
 
virtual int get_hp (const bodypart_id &bp) const
 
virtual int get_hp () const
 
virtual int get_hp_max (const bodypart_id &bp) const
 
virtual int get_hp_max () const
 
virtual int hp_percentage () const =0
 
virtual bool has_flag (const m_flag) const
 
virtual bool uncanny_dodge ()
 
anatomy_id get_anatomy () const
 
void set_anatomy (anatomy_id anat)
 
bodypart_id get_random_body_part (bool main=false) const
 
std::vector< bodypart_idget_all_body_parts (bool only_main=false) const
 Returns body parts this creature have. More...
 
const std::map< bodypart_str_id, bodypart > & get_body () const
 
void set_body ()
 
bodypartget_part (const bodypart_id &id)
 
bodypart get_part (const bodypart_id &id) const
 
int get_part_hp_cur (const bodypart_id &id) const
 
int get_part_hp_max (const bodypart_id &id) const
 
int get_part_healed_total (const bodypart_id &id) const
 
void set_part_hp_cur (const bodypart_id &id, int set)
 
void set_part_hp_max (const bodypart_id &id, int set)
 
void set_part_healed_total (const bodypart_id &id, int set)
 
void mod_part_hp_cur (const bodypart_id &id, int mod)
 
void mod_part_hp_max (const bodypart_id &id, int mod)
 
void mod_part_healed_total (const bodypart_id &id, int mod)
 
void set_all_parts_hp_cur (int set)
 
void set_all_parts_hp_to_max ()
 
virtual int get_speed_base () const
 
virtual int get_speed_bonus () const
 
virtual int get_block_bonus () const
 
virtual float get_dodge_bonus () const
 
virtual float get_hit_bonus () const
 
virtual void set_num_blocks_bonus (int nblocks)
 
virtual void mod_num_dodges_bonus (int ndodges)
 
virtual void set_armor_bash_bonus (int nbasharm)
 
virtual void set_armor_cut_bonus (int ncutarm)
 
virtual void set_armor_bullet_bonus (int nbulletarm)
 
virtual void set_speed_base (int nspeed)
 
virtual void set_speed_bonus (int nspeed)
 
virtual void set_block_bonus (int nblock)
 
virtual void mod_speed_bonus (int nspeed)
 
virtual void mod_block_bonus (int nblock)
 
virtual void set_dodge_bonus (float ndodge)
 
virtual void set_hit_bonus (float nhit)
 
virtual void mod_dodge_bonus (float ndodge)
 
virtual void mod_hit_bonus (float nhit)
 
void draw (const catacurses::window &w, const point &origin, bool inverted) const
 
void draw (const catacurses::window &w, const tripoint &origin, bool inverted) const
 
void describe_infrared (std::vector< std::string > &buf) const
 Describe this creature as seen by the avatar via infrared vision. More...
 
void describe_specials (std::vector< std::string > &buf) const
 Describe this creature as detected by the avatar's special senses. More...
 
virtual void add_msg_if_player (const std::string &) const
 
virtual void add_msg_if_player (const game_message_params &, const std::string &) const
 
void add_msg_if_player (const translation &) const
 
void add_msg_if_player (const game_message_params &, const translation &) const
 
template<typename ... Args>
void add_msg_if_player (const char *const msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_player (const std::string &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_player (const translation &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_player (const game_message_params &params, const char *const msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_player (const game_message_params &params, const std::string &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_player (const game_message_params &params, const translation &msg, Args &&... args) const
 
virtual void add_msg_if_npc (const std::string &) const
 
virtual void add_msg_if_npc (const game_message_params &, const std::string &) const
 
void add_msg_if_npc (const translation &) const
 
void add_msg_if_npc (const game_message_params &, const translation &) const
 
template<typename ... Args>
void add_msg_if_npc (const char *const msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_npc (const std::string &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_npc (const translation &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_npc (const game_message_params &params, const char *const msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_npc (const game_message_params &params, const std::string &msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_if_npc (const game_message_params &params, const translation &msg, Args &&... args) const
 
virtual void add_msg_player_or_npc (const std::string &, const std::string &) const
 
virtual void add_msg_player_or_npc (const game_message_params &, const std::string &, const std::string &) const
 
void add_msg_player_or_npc (const translation &, const translation &) const
 
void add_msg_player_or_npc (const game_message_params &, const translation &, const translation &) const
 
template<typename ... Args>
void add_msg_player_or_npc (const char *const player_msg, const char *const npc_msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_npc (const std::string &player_msg, const std::string &npc_msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_npc (const translation &player_msg, const translation &npc_msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_npc (const game_message_params &params, const char *const player_msg, const char *const npc_msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_npc (const game_message_params &params, const std::string &player_msg, const std::string &npc_msg, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_npc (const game_message_params &params, const translation &player_msg, const translation &npc_msg, Args &&... args) const
 
virtual void add_msg_player_or_say (const std::string &, const std::string &) const
 
virtual void add_msg_player_or_say (const game_message_params &, const std::string &, const std::string &) const
 
void add_msg_player_or_say (const translation &, const translation &) const
 
void add_msg_player_or_say (const game_message_params &, const translation &, const translation &) const
 
template<typename ... Args>
void add_msg_player_or_say (const char *const player_msg, const char *const npc_speech, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_say (const std::string &player_msg, const std::string &npc_speech, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_say (const translation &player_msg, const translation &npc_speech, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_say (const game_message_params &params, const char *const player_msg, const char *const npc_speech, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_say (const game_message_params &params, const std::string &player_msg, const std::string &npc_speech, Args &&... args) const
 
template<typename ... Args>
void add_msg_player_or_say (const game_message_params &params, const translation &player_msg, const translation &npc_speech, Args &&... args) const
 
virtual nc_color basic_symbol_color () const =0
 
virtual bool is_symbol_highlighted () const
 
effects_map get_all_effects () const
 
body_part select_body_part (Creature *source, int hit_roll) const
 
std::string replace_with_npc_name (std::string input) const
 This function replaces the "<npcname>" substring with the disp_name of this creature. More...
 
- Public Member Functions inherited from visitable< Character >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static hp_part bp_to_hp (body_part bp)
 Converts a body_part to an hp_part. More...
 
static body_part hp_to_bp (hp_part hpart)
 Converts an hp_part to a body_part. More...
 
static int worn_position_to_index (int position)
 
static int floor_bedding_warmth (const tripoint &pos)
 Warmth from terrain, furniture, vehicle furniture and traps. More...
 
static int floor_item_warmth (const tripoint &pos)
 Warmth from clothing on the floor. More...
 
- Static Public Member Functions inherited from Creature
static std::string attitude_raw_string (Attitude att)
 Simplified attitude string for unlocalized needs. More...
 
static const std::pair< translation, nc_color > & get_attitude_ui_data (Attitude att)
 Creature Attitude as String and color. More...
 
static void load_hit_range (const JsonObject &)
 
static void reset_hit_range ()
 

Public Attributes

bool death_drops = true
 
bool controlling_vehicle = false
 
int str_max = 0
 
int dex_max = 0
 
int int_max = 0
 
int per_max = 0
 
int str_cur = 0
 
int dex_cur = 0
 
int int_cur = 0
 
int per_cur = 0
 
int blocks_left = 0
 
int dodges_left = 0
 
double recoil = MAX_RECOIL
 
profession_id prof
 
std::string custom_profession
 
bool reach_attacking = false
 
std::vector< tripoint_abs_omtomt_path
 
pimpl< known_magicmagic
 
std::string name
 
bool male = true
 
std::list< itemworn
 
std::array< int, num_hp_partsdamage_bandaged
 
std::array< int, num_hp_partsdamage_disinfected
 
bool nv_cached = false
 
bool in_vehicle = false
 
bool hauling = false
 
player_activity stashed_outbounds_activity
 
player_activity stashed_outbounds_backlog
 
player_activity activity
 
std::list< player_activitybacklog
 
cata::optional< tripointdestination_point
 
inventory inv
 
itype_id last_item
 
item weapon
 
int scent = 0
 
pimpl< bionic_collectionmy_bionics
 
pimpl< character_martial_artsmartial_arts_data
 
stomach_contents stomach
 
pimpl< consumption_history_tconsumption_history
 
int oxygen = 0
 
int tank_plut = 0
 
int reactor_plut = 0
 
int slow_rad = 0
 
int focus_pool = 0
 
int cash = 0
 
std::set< character_idfollower_ids
 
weak_ptr_fast< Creaturelast_target
 
cata::optional< tripointlast_target_pos
 
item_location ammo_location
 
std::set< tripoint_abs_omtcamps
 
time_point cached_time
 
std::vector< addictionaddictions
 
shared_ptr_fast< monstermounted_creature
 
int mounted_creature_id = 0
 
int activity_vehicle_part_index = -1
 
std::array< int, num_hp_partshealed_total
 
std::map< std::string, int > mutation_category_level
 
std::array< int, num_bptemp_cur
 
std::array< int, num_bpfrostbite_timer
 
std::array< int, num_bptemp_conv
 
std::array< int, num_bpbody_wetness
 
std::array< int, num_bpdrench_capacity
 
time_point next_climate_control_check
 
bool last_climate_control_ret = false
 
- Public Attributes inherited from Creature
FacingDirection facing = FD_RIGHT
 return the direction the creature is facing, for sdl horizontal flip More...
 
int moves = 0
 
bool underwater = false
 

Static Public Attributes

static const std::vector< material_idfleshy = { material_id( "flesh" ), material_id( "hflesh" ) }
 
- Static Public Attributes inherited from Creature
static const std::map< std::string, m_sizesize_map
 
static const std::set< material_idcmat_flesh
 
static const std::set< material_idcmat_fleshnveg
 
static const std::set< material_idcmat_flammable
 
static const std::set< material_idcmat_flameres
 
static std::vector< int > dispersion_for_even_chance_of_good_hit = default_dispersion_for_ecogh
 

Protected Member Functions

void do_skill_rust ()
 
void apply_mods (const trait_id &mut, bool add_remove)
 Applies stat mods to character. More...
 
char_encumbrance_data calc_encumbrance () const
 Recalculate encumbrance for all body parts. More...
 
char_encumbrance_data calc_encumbrance (const item &new_item) const
 Recalculate encumbrance for all body parts as if new_item was also worn. More...
 
void mut_cbm_encumb (char_encumbrance_data &vals) const
 Applies encumbrance from mutations and bionics only. More...
 
std::list< item >::iterator position_to_wear_new_item (const item &new_item)
 Return the position in the worn list where new_item would be put by default. More...
 
void item_encumb (char_encumbrance_data &vals, const item &new_item) const
 Applies encumbrance from items only If new_item is not null, then calculate under the asumption that it is added to existing work items. More...
 
void on_damage_of_type (int adjusted_damage, damage_type type, const bodypart_id &bp) override
 
 Character ()
 
 Character (Character &&)
 
Characteroperator= (Character &&)
 
void store (JsonOut &json) const
 Load variables from json into object. More...
 
void load (const JsonObject &data)
 Gather variables for saving. More...
 
- Protected Member Functions inherited from Creature
void set_killer (Creature *killer)
 
virtual void process_one_effect (effect &e, bool is_new)=0
 Processes one effect on the Creature. More...
 
 Creature ()
 
 Creature (const Creature &)=default
 
 Creature (Creature &&)=default
 
Creatureoperator= (const Creature &)=default
 
Creatureoperator= (Creature &&)=default
 
void store (JsonOut &jsout) const
 These two functions are responsible for storing and loading the members of this class to/from json data. More...
 
void load (const JsonObject &jsin)
 

Protected Attributes

std::array< std::array< int, NUM_WATER_TOLERANCE >, num_bpmut_drench
 
tripoint position
 
int str_bonus = 0
 Bonuses to stats, calculated each turn. More...
 
int dex_bonus = 0
 
int per_bonus = 0
 
int int_bonus = 0
 
int healthy = 0
 How healthy the character is. More...
 
int healthy_mod = 0
 
int init_age = 25
 age in years at character creation More...
 
int init_height = 175
 height at character creation More...
 
m_size size_class = MS_MEDIUM
 Size class of character. More...
 
trap_map known_traps
 
pimpl< char_encumbrance_dataencumbrance_cache
 
std::map< std::string, double > cached_info
 
bool bio_soporific_powered_at_last_sleep_check = false
 
time_point last_sleep_check = calendar::turn_zero
 last time we checked for sleep More...
 
std::map< faction_id, std::pair< int, time_point > > warning_record
 warnings from a faction about bad behavior More...
 
std::unordered_map< trait_id, trait_datamy_mutations
 Traits / mutations of the character. More...
 
std::unordered_set< trait_idmy_traits
 Contains mutation ids of the base traits. More...
 
std::vector< const mutation_branch * > cached_mutations
 Pointers to mutation branches in my_mutations. More...
 
pimpl< SkillLevelMap_skills
 
std::bitset< NUM_VISION_MODESvision_mode_cache
 
float nv_range = 0
 
int sight_max = 0
 
time_point time_died = calendar::before_time_starts
 
pimpl< pathfinding_settingspath_settings
 Cache for pathfinding settings. More...
 
int faction_api_version = 2
 
faction_id fac_id
 
factionmy_fac = nullptr
 
character_movemode move_mode = CMM_WALK
 
std::map< vitamin_id, int > vitamin_levels
 Current deficiency/excess quantity for each vitamin. More...
 
pimpl< player_moralemorale
 
pimpl< enchantmentenchantment_cache
 
std::unordered_map< point_abs_omt, time_durationovermap_time
 Amount of time the player has spent in each overmap tile. More...
 
- Protected Attributes inherited from Creature
Creaturekiller = nullptr
 
pimpl< effects_mapeffects
 
std::unordered_map< std::string, std::string > values
 
int num_blocks = 0
 
int num_dodges = 0
 
int num_blocks_bonus = 0
 
int num_dodges_bonus = 0
 
int armor_bash_bonus = 0
 
int armor_cut_bonus = 0
 
int armor_bullet_bonus = 0
 
int speed_base = 0
 
int speed_bonus = 0
 
float dodge_bonus = 0.0
 
int block_bonus = 0
 
float hit_bonus = 0.0
 
bool fake = false
 

Private Member Functions

bool valid_aoe_technique (Creature &t, const ma_technique &technique)
 Check if an area-of-effect technique has valid targets. More...
 
bool valid_aoe_technique (Creature &t, const ma_technique &technique, std::vector< Creature * > &targets)
 
int get_mod (const trait_id &mut, const std::string &arg) const
 Retrieves a stat mod of a mutation. More...
 
void apply_skill_boost ()
 Applies skill-based boosts to stats. More...
 
void old_mutate ()
 
void suffer_water_damage (const mutation_branch &mdata)
 suffer() subcalls More...
 
void suffer_mutation_power (const mutation_branch &mdata, Character::trait_data &tdata)
 
void suffer_while_underwater ()
 
void suffer_from_addictions ()
 
void suffer_while_awake (int current_stim)
 
void suffer_from_chemimbalance ()
 
void suffer_from_schizophrenia ()
 
void suffer_from_asthma (int current_stim)
 
void suffer_from_pain ()
 
void suffer_in_sunlight ()
 
void suffer_from_sunburn ()
 
void suffer_from_other_mutations ()
 
void suffer_from_radiation ()
 
void suffer_from_bad_bionics ()
 
void suffer_from_artifacts ()
 
void suffer_from_stimulants (int current_stim)
 
void suffer_without_sleep (int sleep_deprivation)
 
bool is_visible_in_range (const Creature &critter, int range) const
 Check whether the other creature is in range and can be seen by this creature. More...
 

Private Attributes

player_activity destination_activity
 
character_id id
 
units::energy power_level
 
units::energy max_power_level
 
int stored_calories = 0
 Needs (hunger, starvation, thirst, fatigue, etc.) More...
 
int thirst = 0
 
int stamina = 0
 
int fatigue = 0
 
int sleep_deprivation = 0
 
bool check_encumbrance = true
 
int stim = 0
 
int pkill = 0
 
int radiation = 0
 
std::vector< tripointauto_move_route
 
cata::optional< tripointnext_expected_position
 
scenttype_id type_of_scent
 
struct weighted_int_list< std::string > melee_miss_reasons
 
int cached_moves = 0
 
tripoint cached_position
 
inventory cached_crafting_inventory
 

Additional Inherited Members

Detailed Description

Definition at line 201 of file character.h.

Member Typedef Documentation

◆ trap_map

using Character::trap_map = std::map<tripoint, std::string>

Definition at line 2003 of file character.h.

Member Enumeration Documentation

◆ comfort_level

enum class Character::comfort_level
strong
Enumerator
impossible 
uncomfortable 
neutral 
slightly_comfortable 
comfortable 
very_comfortable 

Definition at line 230 of file character.h.

230 {
231 impossible = -999,
232 uncomfortable = -7,
233 neutral = 0,
234 slightly_comfortable = 3,
235 comfortable = 5,
236 very_comfortable = 10
237 };

◆ water_tolerance

Enumerator
WT_IGNORED 
WT_NEUTRAL 
WT_GOOD 
NUM_WATER_TOLERANCE 

Definition at line 775 of file character.h.

775 {
776 WT_IGNORED = 0,
778 WT_GOOD,
780 };
@ WT_NEUTRAL
Definition: character.h:777
@ WT_IGNORED
Definition: character.h:776
@ NUM_WATER_TOLERANCE
Definition: character.h:779

Constructor & Destructor Documentation

◆ Character() [1/3]

Character::Character ( const Character )
delete

◆ ~Character()

Character::~Character ( )
overridedefault

◆ Character() [2/3]

Character::Character ( )
protected

Definition at line 394 of file character.cpp.

394 :
396 damage_bandaged( {{ 0 }} ),
397 damage_disinfected( {{ 0 }} ),
399 id( -1 ),
402{
403 str_max = 0;
404 dex_max = 0;
405 per_max = 0;
406 int_max = 0;
407 str_cur = 0;
408 dex_cur = 0;
409 per_cur = 0;
410 int_cur = 0;
411 str_bonus = 0;
412 dex_bonus = 0;
413 per_bonus = 0;
414 int_bonus = 0;
415 healthy = 0;
416 healthy_mod = 0;
417 thirst = 0;
418 fatigue = 0;
420 set_rad( 0 );
421 tank_plut = 0;
422 reactor_plut = 0;
423 slow_rad = 0;
424 set_stim( 0 );
425 set_stamina( 10000 ); //Temporary value for stamina. It will be reset later from external json option.
426 set_anatomy( anatomy_id("human_anatomy") );
427 update_type_of_scent( true );
428 pkill = 0;
431 healed_total = { { 0, 0, 0, 0, 0, 0 } };
432
433 name.clear();
434 custom_profession.clear();
436
437 *path_settings = pathfinding_settings{ 0, 1000, 1000, 0, true, true, true, false, true };
438
441 temp_cur.fill( BODYTEMP_NORM );
442 frostbite_timer.fill( 0 );
443 temp_conv.fill( BODYTEMP_NORM );
444
445 body_wetness.fill( 0 );
446
459}
string_id< anatomy > anatomy_id
Definition: anatomy.h:14
@ bp_foot_l
Definition: bodypart.h:50
@ bp_leg_r
Definition: bodypart.h:49
@ bp_eyes
Definition: bodypart.h:42
@ bp_hand_l
Definition: bodypart.h:46
@ bp_arm_l
Definition: bodypart.h:44
@ bp_leg_l
Definition: bodypart.h:48
@ bp_hand_r
Definition: bodypart.h:47
@ bp_head
Definition: bodypart.h:41
@ bp_torso
Definition: bodypart.h:40
@ bp_mouth
Definition: bodypart.h:43
@ bp_foot_r
Definition: bodypart.h:51
@ bp_arm_r
Definition: bodypart.h:45
@ CMM_WALK
Definition: character.h:101
bool last_climate_control_ret
Definition: character.h:2220
character_movemode move_mode
Definition: character.h:2132
int str_max
Definition: character.h:241
std::array< int, num_bp > frostbite_timer
Definition: character.h:2215
void update_type_of_scent(bool init=false)
Definition: character.cpp:8740
int str_cur
Definition: character.h:246
int str_bonus
Bonuses to stats, calculated each turn.
Definition: character.h:2061
profession_id prof
Definition: character.h:562
int dex_cur
Definition: character.h:247
std::array< int, num_bp > temp_conv
Definition: character.h:2215
int max_stored_kcal() const
Definition: character.cpp:4333
int per_max
Definition: character.h:244
void set_stim(int new_stim)
Definition: character.cpp:7180
void set_stamina(int new_stamina)
Definition: character.cpp:7222
std::string name
Definition: character.h:1512
std::array< int, num_bp > body_wetness
Definition: character.h:2216
time_point next_climate_control_check
Definition: character.h:2219
int stored_calories
Needs (hunger, starvation, thirst, fatigue, etc.)
Definition: character.h:2180
int per_bonus
Definition: character.h:2063
time_point cached_time
Definition: character.h:1552
std::string custom_profession
Definition: character.h:563
int dex_bonus
Definition: character.h:2062
pimpl< pathfinding_settings > path_settings
Cache for pathfinding settings.
Definition: character.h:2121
std::array< int, num_hp_parts > damage_bandaged
Definition: character.h:1516
character_id id
Definition: character.h:2174
int healthy
How healthy the character is.
Definition: character.h:2067
int sleep_deprivation
Definition: character.h:2186
int int_cur
Definition: character.h:248
int int_max
Definition: character.h:243
int reactor_plut
Definition: character.h:1540
int fatigue
Definition: character.h:2185
std::array< int, num_bp > drench_capacity
Definition: character.h:2217
std::array< int, num_bp > temp_cur
Definition: character.h:2215
void initialize_stomach_contents()
Definition: stomach.cpp:195
std::array< int, num_hp_parts > healed_total
Definition: character.h:1727
void set_rad(int new_rad)
Definition: character.cpp:7195
int slow_rad
Definition: character.h:1541
int per_cur
Definition: character.h:249
int tank_plut
Definition: character.h:1539
int healthy_mod
Definition: character.h:2068
int dex_max
Definition: character.h:242
int thirst
Definition: character.h:2182
cata::optional< tripoint > next_expected_position
Definition: character.h:2196
int int_bonus
Definition: character.h:2064
std::array< int, num_hp_parts > damage_disinfected
Definition: character.h:1516
void set_anatomy(anatomy_id anat)
Definition: creature.cpp:1522
static const profession_id & generic()
Definition: profession.cpp:248
const time_point before_time_starts
A time point that is always before the current turn, even when the game has just started.
Definition: calendar.cpp:25
static constexpr nullopt_t nullopt
Definition: optional.h:22
static constexpr int BODYTEMP_NORM
Level 1 hotness.
Definition: weather.h:36

◆ Character() [3/3]

Character::Character ( Character &&  )
protecteddefault

Member Function Documentation

◆ absorb_hit()

void Character::absorb_hit ( const bodypart_id bp,
damage_instance dam 
)
overridevirtual

Runs through all bionics and armor on a part and reduces damage through their armor_absorb.

Implements Creature.

Definition at line 8165 of file character.cpp.

8166{
8167 std::list<item> worn_remains;
8168 bool armor_destroyed = false;
8169
8170 for( damage_unit &elem : dam.damage_units ) {
8171 if( elem.amount < 0 ) {
8172 // Prevents 0 damage hits (like from hallucinations) from ripping armor
8173 elem.amount = 0;
8174 continue;
8175 }
8176
8177 // The bio_ads CBM absorbs percentage melee damage and ranged damage (where possible) after armour.
8178 if( has_active_bionic( bio_ads ) && ( elem.amount > 0 ) && ( elem.type == DT_BASH ||
8179 elem.type == DT_CUT || elem.type == DT_STAB || elem.type == DT_BULLET ) ) {
8180 float elem_multi = 1;
8181 // HACK: In the future this hopefully gets streamlined.
8182 const auto &all_bionics = get_bionics();
8183 size_t index;
8184 for( index = 0; index < all_bionics.size(); index++ ) {
8185 if( all_bionics[index] == bio_ads ) {
8186 break;
8187 }
8188 }
8189 bionic &bio = bionic_at_index( index );
8190 // HACK: Halves charge rate when hit for the next 3 turns, doesn't stack. See bionics.cpp for more information.
8191 bio.charge_timer = 6;
8192 // Bullet affected significantly more than stab, stab more than cut, cut more than bash.
8193 if( elem.type == DT_BASH ) {
8194 elem_multi = 0.8;
8195 } else if( elem.type == DT_CUT ) {
8196 elem_multi = 0.7;
8197 } else if( elem.type == DT_STAB ) {
8198 elem_multi = 0.55;
8199 } else if( elem.type == DT_BULLET ) {
8200 elem_multi = 0.25;
8201 }
8202 units::energy ads_cost = elem.amount * 500_J;
8203 if( bio.energy_stored >= ads_cost ) {
8204 dam.mult_damage( elem_multi );
8205 bio.energy_stored -= ads_cost;
8206 } else if( bio.energy_stored < ads_cost && bio.energy_stored != 0_kJ ) {
8207 // If you get hit and you lack energy it either deactivates, or deactivates and shorts out.
8208 // Either way you still get protection.
8209 dam.mult_damage( elem_multi );
8210 bio.energy_stored = 0_kJ;
8211 deactivate_bionic( index );
8212 const units::energy shatter_thresh = ( elem.type == DT_BULLET ) ? 20_kJ : 15_kJ;
8213 if( ads_cost >= shatter_thresh ) {
8214 if( bio.incapacitated_time == 0_turns ) {
8215 add_msg_if_player( m_bad, _( "Your forcefield shatters and the feedback shorts out the %s!" ),
8216 bio.info().name );
8217 }
8218 int over = units::to_kilojoule( ads_cost - ( shatter_thresh - 5_kJ ) );
8219 bio.incapacitated_time += ( ( over / 5 ) ) * 1_turns;
8220 } else {
8221 add_msg_if_player( m_bad, _( "Your forcefield crackles and the %s powers down." ),
8222 bio.info().name );
8223 }
8224 } else {
8225 //You tried to (re)activate it and immediately enter combat, no mitigation for you.
8226 deactivate_bionic( index );
8227 add_msg_if_player( m_bad, _( "The %s is interrupted and powers down." ), bio.info().name );
8228 }
8229 }
8230
8231 armor_enchantment_adjust( *this, elem );
8232
8233 // Only the outermost armor can be set on fire
8234 bool outermost = true;
8235 // The worn vector has the innermost item first, so
8236 // iterate reverse to damage the outermost (last in worn vector) first.
8237 for( auto iter = worn.rbegin(); iter != worn.rend(); ) {
8238 item &armor = *iter;
8239
8240 if( !armor.covers( bp->token ) ) {
8241 ++iter;
8242 continue;
8243 }
8244
8245 const std::string pre_damage_name = armor.tname();
8246 bool destroy = false;
8247
8248 item_armor_enchantment_adjust( *this, elem, armor );
8249 // Heat damage can set armor on fire
8250 // Even though it doesn't cause direct physical damage to it
8251 if( outermost && elem.type == DT_HEAT && elem.amount >= 1.0f ) {
8252 // TODO: Different fire intensity values based on damage
8253 fire_data frd{ 2 };
8254 destroy = armor.burn( frd );
8255 int fuel = roll_remainder( frd.fuel_produced );
8256 if( fuel > 0 ) {
8257 add_effect( effect_onfire, time_duration::from_turns( fuel + 1 ), bp->token, 0, false, true );
8258 }
8259 }
8260
8261 if( !destroy ) {
8262 destroy = armor_absorb( elem, armor );
8263 }
8264
8265 if( destroy ) {
8266 if( g->u.sees( *this ) ) {
8267 SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ),
8268 m_neutral, _( "destroyed" ), m_info );
8269 }
8270 destroyed_armor_msg( *this, pre_damage_name );
8271 armor_destroyed = true;
8272 armor.on_takeoff( *this );
8273 for( const item *it : armor.contents.all_items_top() ) {
8274 worn_remains.push_back( *it );
8275 }
8276 // decltype is the type name of the iterator, note that reverse_iterator::base returns the
8277 // iterator to the next element, not the one the revers_iterator points to.
8278 // http://stackoverflow.com/questions/1830158/how-to-call-erase-with-a-reverse-iterator
8279 iter = decltype( iter )( worn.erase( --( iter.base() ) ) );
8280 } else {
8281 ++iter;
8282 outermost = false;
8283 }
8284 }
8285
8286 passive_absorb_hit( bp, elem );
8287
8288 if( elem.type == DT_BASH ) {
8289 if( has_trait( trait_LIGHT_BONES ) ) {
8290 elem.amount *= 1.4;
8291 }
8292 if( has_trait( trait_HOLLOW_BONES ) ) {
8293 elem.amount *= 1.8;
8294 }
8295 }
8296
8297 elem.amount = std::max( elem.amount, 0.0f );
8298 }
8299 map &here = get_map();
8300 for( item &remain : worn_remains ) {
8301 here.add_item_or_charges( pos(), remain );
8302 }
8303 if( armor_destroyed ) {
8305 }
8306}
static const trait_id trait_HOLLOW_BONES("HOLLOW_BONES")
static void item_armor_enchantment_adjust(Character &guy, damage_unit &du, item &armor)
Definition: character.cpp:8091
static void destroyed_armor_msg(Character &who, const std::string &pre_damage_name)
Definition: character.cpp:8077
static const bionic_id bio_ads("bio_ads")
static void armor_enchantment_adjust(Character &guy, damage_unit &du)
Definition: character.cpp:8129
static const trait_id trait_LIGHT_BONES("LIGHT_BONES")
static const efftype_id effect_onfire("onfire")
bionic & bionic_at_index(int i)
Returns the bionic at a given index in my_bionics[].
Definition: bionics.cpp:2661
int posx() const override
Definition: character.h:781
int posy() const override
Definition: character.h:784
std::list< item > worn
Definition: character.h:1515
bool armor_absorb(damage_unit &du, item &armor)
Reduces and mutates du, prints messages about armor taking damage.
Definition: character.cpp:8308
bool deactivate_bionic(int b, bool eff_only=false)
Handles bionic deactivation effects of the entered bionic, returns if anything deactivated.
Definition: bionics.cpp:1066
void drop_invalid_inventory()
Definition: character.cpp:3201
void passive_absorb_hit(const bodypart_id &bp, damage_unit &du) const
Check for relevant passive, non-clothing that can absorb damage, and reduce by specified damage unit.
Definition: character.cpp:8058
const tripoint & pos() const override
Definition: character.cpp:714
std::vector< bionic_id > get_bionics() const
Definition: character.cpp:1871
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:103
bool has_active_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id and it is powered on.
Definition: character.cpp:1890
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:980
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:593
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
Definition: item.h:176
item_contents contents
Definition: item.h:2157
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4438
void on_takeoff(Character &p)
Callback when a character takes off an item.
Definition: item.cpp:4281
bool burn(fire_data &frd)
Burns the item.
Definition: item.cpp:8116
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:742
Manage and cache data about a part of the map.
Definition: map.h:385
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4214
void add(const point &pos, direction p_oDir, const std::string &p_sText, game_message_type p_gmt, const std::string &p_sText2="", game_message_type p_gmt2=m_neutral, const std::string &p_sType="")
Definition: output.cpp:1757
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
@ DT_BULLET
Definition: damage.h:31
@ DT_HEAT
Definition: damage.h:28
@ m_neutral
Definition: enums.h:260
@ m_info
Definition: enums.h:258
@ m_bad
Definition: enums.h:254
std::unique_ptr< game > g
Definition: game.cpp:269
map & get_map()
Definition: map.cpp:142
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
std::string remove_color_tags(const std::string &s)
Removes the color tags from the input string.
Definition: output.cpp:145
scrollingcombattext SCT
Definition: output.cpp:65
int roll_remainder(double value)
Definition: rng.cpp:96
translation name
Definition: bionics.h:34
const bionic_data & info() const
Definition: bionics.h:168
int charge_timer
Definition: bionics.h:151
units::energy energy_stored
Definition: bionics.h:161
time_duration incapacitated_time
Definition: bionics.h:159
std::vector< damage_unit > damage_units
Definition: damage.h:52
void mult_damage(double multiplier, bool pre_armor=false)
Definition: damage.cpp:48
float amount
Definition: damage.h:37
damage_type type
Definition: damage.h:36
Contains the state of a fire in one tile on one turn.
Definition: fire.h:18
Definition: point.h:35
#define _(msg)
Definition: translations.h:116

References _, scrollingcombattext::add(), Creature::add_effect(), map::add_item_or_charges(), Creature::add_msg_if_player(), item_contents::all_items_top(), damage_unit::amount, armor_absorb(), armor_enchantment_adjust(), bio_ads, bionic_at_index(), item::burn(), bionic::charge_timer, item::contents, item::covers(), damage_instance::damage_units, deactivate_bionic(), destroyed_armor_msg(), drop_invalid_inventory(), DT_BASH, DT_BULLET, DT_CUT, DT_HEAT, DT_STAB, effect_onfire, bionic::energy_stored, time_duration::from_turns(), g, get_bionics(), get_map(), has_active_bionic(), has_trait(), bionic::incapacitated_time, bionic::info(), item_armor_enchantment_adjust(), m_bad, m_info, m_neutral, damage_instance::mult_damage(), bionic_data::name, NORTH, item::on_takeoff(), passive_absorb_hit(), pos(), posx(), posy(), remove_color_tags(), roll_remainder(), SCT, item::tname(), units::to_kilojoule(), trait_HOLLOW_BONES, trait_LIGHT_BONES, damage_unit::type, and worn.

◆ action_taken()

void Character::action_taken ( )

Called after every action, invalidates player caches.

Definition at line 877 of file character.cpp.

878{
879 nv_cached = false;
880}
bool nv_cached
Definition: character.h:1517

References nv_cached.

Referenced by game::do_turn().

◆ activate_bionic()

bool Character::activate_bionic ( int  b,
bool  eff_only = false 
)

Handles bionic activation effects of the entered bionic, returns if anything activated.

Definition at line 532 of file bionics.cpp.

533{
534 bionic &bio = ( *my_bionics )[b];
535 const bool mounted = is_mounted();
536 if( bio.incapacitated_time > 0_turns ) {
537 add_msg( m_info, _( "Your %s is shorting out and can't be activated." ),
538 bio.info().name );
539 return false;
540 }
541
542 // eff_only means only do the effect without messing with stats or displaying messages
543 if( !eff_only ) {
544 if( bio.powered ) {
545 // It's already on!
546 return false;
547 }
548 if( !enough_power_for( bio.id ) ) {
549 add_msg_if_player( m_info, _( "You don't have the power to activate your %s." ),
550 bio.info().name );
551 return false;
552 }
553
554 // HACK: burn_fuel() doesn't check for available fuel in remote source on start.
555 // If CBM is successfully activated, the check will occur when it actually tries to draw power
556 if( !bio.info().is_remote_fueled ) {
557 if( !burn_fuel( b, true ) ) {
558 return false;
559 }
560 }
561
562 // We can actually activate now, do activation-y things
564
565 bio.powered = bio.info().has_flag( flag_BIONIC_TOGGLED ) || bio.info().charge_time > 0;
566
567 if( bio.info().charge_time > 0 ) {
568 bio.charge_timer = bio.info().charge_time;
569 }
570 if( !bio.id->enchantments.empty() ) {
572 }
573 }
574
575 auto add_msg_activate = [&]() {
576 if( !eff_only && !bio.is_auto_start_keep_full() ) {
577 add_msg_if_player( m_info, _( "You activate your %s." ), bio.info().name );
578 }
579 };
580 auto refund_power = [&]() {
581 if( !eff_only ) {
583 }
584 };
585
586 item tmp_item;
587 const w_point &weatherPoint = get_weather().get_precise();
588
589 map &here = get_map();
590 // On activation effects go here
591 if( bio.info().has_flag( flag_BIONIC_GUN ) ) {
592 add_msg_activate();
593 refund_power(); // Power usage calculated later, in avatar_action::fire
595 bio.info().power_activate );
596 } else if( bio.info().has_flag( flag_BIONIC_WEAPON ) ) {
598 add_msg_if_player( m_info, _( "Deactivate your %s first!" ), weapon.tname() );
599 refund_power();
600 bio.powered = false;
601 return false;
602 }
603
604 if( !weapon.is_null() ) {
605 const std::string query = string_format( _( "Stop wielding %s?" ), weapon.tname() );
606 if( !dispose_item( item_location( *this, &weapon ), query ) ) {
607 refund_power();
608 bio.powered = false;
609 return false;
610 }
611 }
612
613 add_msg_activate();
614 weapon = item( bio.info().fake_item );
615 weapon.invlet = '#';
616 if( bio.ammo_count > 0 ) {
619 }
620 } else if( bio.id == bio_ears && has_active_bionic( bio_earplugs ) ) {
621 add_msg_activate();
622 for( bionic &bio : *my_bionics ) {
623 if( bio.id == bio_earplugs ) {
624 bio.powered = false;
625 add_msg_if_player( m_info, _( "Your %s automatically turn off." ),
626 bio.info().name );
627 }
628 }
629 } else if( bio.id == bio_earplugs && has_active_bionic( bio_ears ) ) {
630 add_msg_activate();
631 for( bionic &bio : *my_bionics ) {
632 if( bio.id == bio_ears ) {
633 bio.powered = false;
634 add_msg_if_player( m_info, _( "Your %s automatically turns off." ),
635 bio.info().name );
636 }
637 }
638 } else if( bio.id == bio_evap ) {
639 add_msg_activate();
640 const w_point &weatherPoint = get_weather().get_precise();
641 int humidity = get_local_humidity( weatherPoint.humidity, get_weather().weather_id,
642 g->is_sheltered( g->u.pos() ) );
643 // thirst units = 5 mL
644 int water_available = std::lround( humidity * 3.0 / 100.0 );
645 if( water_available == 0 ) {
646 bio.powered = false;
647 add_msg_if_player( m_bad, _( "There is not enough humidity in the air for your %s to function." ),
648 bio.info().name );
649 return false;
650 } else if( water_available == 1 ) {
652 _( "Your %s issues a low humidity warning. Efficiency will be reduced." ),
653 bio.info().name );
654 }
655 } else if( bio.id == bio_tools ) {
656 add_msg_activate();
658 } else if( bio.id == bio_cqb ) {
659 add_msg_activate();
660 const avatar *you = as_avatar();
661 if( you && !martial_arts_data->pick_style( *you ) ) {
662 bio.powered = false;
663 add_msg_if_player( m_info, _( "You change your mind and turn it off." ) );
664 return false;
665 }
666 } else if( bio.id == bio_resonator ) {
667 add_msg_activate();
668 //~Sound of a bionic sonic-resonator shaking the area
669 sounds::sound( pos(), 30, sounds::sound_t::combat, _( "VRRRRMP!" ), false, "bionic",
670 static_cast<std::string>( bio_resonator ) );
671 for( const tripoint &bashpoint : here.points_in_radius( pos(), 1 ) ) {
672 here.bash( bashpoint, 110 );
673 // Multibash effect, so that doors &c will fall
674 here.bash( bashpoint, 110 );
675 here.bash( bashpoint, 110 );
676 }
677
678 mod_moves( -100 );
679 } else if( bio.id == bio_time_freeze ) {
680 if( mounted ) {
681 refund_power();
682 add_msg_if_player( m_info, _( "You cannot activate %s while mounted." ), bio.info().name );
683 return false;
684 }
685 add_msg_activate();
686
688 set_power_level( 0_kJ );
689 add_msg_if_player( m_good, _( "Your speed suddenly increases!" ) );
690 if( one_in( 3 ) ) {
691 add_msg_if_player( m_bad, _( "Your muscles tear with the strain." ) );
692 apply_damage( nullptr, bodypart_id( "arm_l" ), rng( 5, 10 ) );
693 apply_damage( nullptr, bodypart_id( "arm_r" ), rng( 5, 10 ) );
694 apply_damage( nullptr, bodypart_id( "leg_l" ), rng( 7, 12 ) );
695 apply_damage( nullptr, bodypart_id( "leg_r" ), rng( 7, 12 ) );
696 apply_damage( nullptr, bodypart_id( "torso" ), rng( 5, 15 ) );
697 }
698 if( one_in( 5 ) ) {
699 add_effect( effect_teleglow, rng( 5_minutes, 40_minutes ) );
700 }
701 } else if( bio.id == bio_teleport ) {
702 if( mounted ) {
703 refund_power();
704 add_msg_if_player( m_info, _( "You cannot activate %s while mounted." ), bio.info().name );
705 return false;
706 }
707 add_msg_activate();
708
709 teleport::teleport( *this );
710 add_effect( effect_teleglow, 30_minutes );
711 mod_moves( -100 );
712 } else if( bio.id == bio_blood_anal ) {
713 add_msg_activate();
715 } else if( bio.id == bio_blood_filter ) {
716 add_msg_activate();
717 static const std::vector<efftype_id> removable = {{
725 }
726 };
727
728 for( const auto &eff : removable ) {
729 remove_effect( eff );
730 }
731 // Purging the substance won't remove the fatigue it caused
734 set_painkiller( 0 );
735 set_stim( 0 );
736 mod_moves( -100 );
737 } else if( bio.id == bio_torsionratchet ) {
738 add_msg_activate();
739 add_msg_if_player( m_info, _( "Your torsion ratchet locks onto your joints." ) );
740 } else if( bio.id == bio_jointservo ) {
741 add_msg_activate();
742 add_msg_if_player( m_info, _( "You can now run faster, assisted by joint servomotors." ) );
743 } else if( bio.id == bio_lighter ) {
744 const cata::optional<tripoint> pnt = choose_adjacent( _( "Start a fire where?" ) );
745 if( pnt && here.is_flammable( *pnt ) ) {
746 add_msg_activate();
747 here.add_field( *pnt, fd_fire, 1 );
748 mod_moves( -100 );
749 } else {
750 refund_power();
751 add_msg_if_player( m_info, _( "There's nothing to light there." ) );
752 return false;
753 }
754 } else if( bio.id == bio_geiger ) {
755 add_msg_activate();
756 add_msg_if_player( m_info, _( "Your radiation level: %d" ), get_rad() );
757 } else if( bio.id == bio_radscrubber ) {
758 add_msg_activate();
759 if( get_rad() > 4 ) {
760 mod_rad( -5 );
761 } else {
762 set_rad( 0 );
763 }
764 } else if( bio.id == bio_adrenaline ) {
765 add_msg_activate();
767 add_msg_if_player( m_bad, _( "Safeguards kick in, and the bionic refuses to activate!" ) );
768 refund_power();
769 return false;
770 } else {
771 add_msg_activate();
772 add_effect( effect_adrenaline, 20_minutes );
773 }
774 } else if( bio.id == bio_emp ) {
775 if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Create an EMP where?" ) ) ) {
776 add_msg_activate();
778 mod_moves( -100 );
779 } else {
780 refund_power();
781 return false;
782 }
783 } else if( bio.id == bio_hydraulics ) {
784 add_msg_activate();
785 add_msg_if_player( m_good, _( "Your muscles hiss as hydraulic strength fills them!" ) );
786 //~ Sound of hissing hydraulic muscle! (not quite as loud as a car horn)
787 sounds::sound( pos(), 19, sounds::sound_t::activity, _( "HISISSS!" ), false, "bionic",
788 static_cast<std::string>( bio_hydraulics ) );
789 } else if( bio.id == bio_water_extractor ) {
790 bool no_target = true;
791 bool extracted = false;
792 for( item &it : here.i_at( pos() ) ) {
793 static const auto volume_per_water_charge = 500_ml;
794 if( it.is_corpse() ) {
795 const int avail = it.get_var( "remaining_water", it.volume() / volume_per_water_charge );
796 if( avail > 0 ) {
797 no_target = false;
798 if( query_yn( _( "Extract water from the %s" ),
799 colorize( it.tname(), it.color_in_inventory() ) ) ) {
800 item water( itype_water_clean, calendar::turn, avail );
801 if( liquid_handler::consume_liquid( water ) ) {
802 add_msg_activate();
803 extracted = true;
804 it.set_var( "remaining_water", static_cast<int>( water.charges ) );
805 }
806 break;
807 }
808 }
809 }
810 }
811 if( no_target ) {
812 add_msg_if_player( m_bad, _( "There is no suitable corpse on this tile." ) );
813 }
814 if( !extracted ) {
815 refund_power();
816 return false;
817 }
818 } else if( bio.id == bio_magnet ) {
819 add_msg_activate();
820 static const std::set<material_id> affected_materials =
821 { material_id( "iron" ), material_id( "steel" ) };
822 // Remember all items that will be affected, then affect them
823 // Don't "snowball" by affecting some items multiple times
824 std::vector<std::pair<item, tripoint>> affected;
825 const units::mass weight_cap = weight_capacity();
826 for( const tripoint &p : here.points_in_radius( pos(), 10 ) ) {
827 if( p == pos() || !here.has_items( p ) || here.has_flag( flag_SEALED, p ) ) {
828 continue;
829 }
830
831 map_stack stack = here.i_at( p );
832 for( auto it = stack.begin(); it != stack.end(); it++ ) {
833 if( it->weight() < weight_cap &&
834 it->made_of_any( affected_materials ) ) {
835 affected.emplace_back( std::make_pair( *it, p ) );
836 stack.erase( it );
837 break;
838 }
839 }
840 }
841
842 for( const std::pair<item, tripoint> &pr : affected ) {
843 projectile proj;
844 proj.speed = 50;
845 proj.impact = damage_instance::physical( pr.first.weight() / 250_gram, 0, 0, 0 );
846 // make the projectile stop one tile short to prevent hitting the player
847 proj.range = rl_dist( pr.second, pos() ) - 1;
848 static const std::set<ammo_effect_str_id> ammo_effects = {{
849 ammo_effect_str_id( "NO_ITEM_DAMAGE" ),
850 ammo_effect_str_id( "DRAW_AS_LINE" ),
851 ammo_effect_str_id( "NO_DAMAGE_SCALING" ),
852 ammo_effect_str_id( "JET" ),
853 }
854 };
855 for( const auto &eff : ammo_effects ) {
856 proj.add_effect( eff );
857 }
858
860 proj, pr.second, pos(), dispersion_sources{ 0 }, this );
861 here.add_item_or_charges( dealt.end_point, pr.first );
862 }
863
864 mod_moves( -100 );
865 } else if( bio.id == bio_lockpick ) {
866 bool used = false;
867 bool tried_lockpick = false;
868 const cata::optional<tripoint> pnt = choose_adjacent( _( "Use your lockpick where?" ) );
869 std::string open_message;
870 if( pnt ) {
871 tried_lockpick = true;
872 ter_id ter_type = g->m.ter( *pnt );
873 furn_id furn_type = g->m.furn( *pnt );
874 lockpicking_open_result lr = get_lockpicking_open_result( ter_type, furn_type );
875 ter_id new_ter_type = lr.new_ter_type;
876 furn_id new_furn_type = lr.new_furn_type;
877 open_message = lr.open_message;
878
879 if( new_ter_type != t_null || new_furn_type != f_null ) {
880 g->m.has_furn( *pnt ) ?
881 g->m.furn_set( *pnt, new_furn_type ) :
882 static_cast<void>( g->m.ter_set( *pnt, new_ter_type ) );
883 used = true;
884 }
885 }
886
887 if( used ) {
888 add_msg_activate();
889 add_msg_if_player( m_good, open_message );
890 mod_moves( -100 );
891 } else {
892 refund_power();
893 if( tried_lockpick ) {
894 add_msg_if_player( m_info, _( "There is nothing to lockpick nearby." ) );
895 }
896 return false;
897 }
898 } else if( bio.id == bio_flashbang ) {
899 add_msg_activate();
900 explosion_handler::flashbang( pos(), true, "explosion" );
901 mod_moves( -100 );
902 } else if( bio.id == bio_shockwave ) {
903 add_msg_activate();
904
906 sw.affects_player = false;
907 sw.radius = 3;
908 sw.force = 4;
909 sw.stun = 2;
910 sw.dam_mult = 8;
911
912 explosion_handler::shockwave( pos(), sw, "explosion" );
913 add_msg_if_player( m_neutral, _( "You unleash a powerful shockwave!" ) );
914 mod_moves( -100 );
915 } else if( bio.id == bio_meteorologist ) {
917 add_msg_activate();
918 // Calculate local wind power
919 int vehwindspeed = 0;
920 if( optional_vpart_position vp = here.veh_at( pos() ) ) {
921 // vehicle velocity in mph
922 vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
923 }
924 const oter_id &cur_om_ter = overmap_buffer.ter( global_omt_location() );
925 /* cache g->get_temperature( player location ) since it is used twice. No reason to recalc */
926 const auto player_local_temp = weather.get_temperature( g->u.pos() );
927 /* windpower defined in internal velocity units (=.01 mph) */
928 double windpower = 100.0f * get_local_windpower( weather.windspeed + vehwindspeed,
929 cur_om_ter, pos(), weather.winddirection, g->is_sheltered( pos() ) );
930 add_msg_if_player( m_info, _( "Temperature: %s." ), print_temperature( player_local_temp ) );
931 add_msg_if_player( m_info, _( "Relative Humidity: %s." ),
933 get_local_humidity( weatherPoint.humidity, weather.weather_id,
934 g->is_sheltered( g->u.pos() ) ) ) );
935 add_msg_if_player( m_info, _( "Pressure: %s." ),
936 print_pressure( static_cast<int>( weatherPoint.pressure ) ) );
937 add_msg_if_player( m_info, _( "Wind Speed: %.1f %s." ),
938 convert_velocity( static_cast<int>( windpower ), VU_WIND ),
940 add_msg_if_player( m_info, _( "Feels Like: %s." ),
943 weatherPoint.humidity,
944 windpower / 100 ) + player_local_temp ) );
945 std::string dirstring = get_dirstring( weather.winddirection );
946 add_msg_if_player( m_info, _( "Wind Direction: From the %s." ), dirstring );
947 } else if( bio.id == bio_remote ) {
948 add_msg_activate();
949 int choice = uilist( _( "Perform which function:" ), {
950 _( "Control vehicle" ), _( "RC radio" )
951 } );
952 if( choice >= 0 && choice <= 1 ) {
953 item ctr;
954 if( choice == 0 ) {
955 ctr = item( "remotevehcontrol", calendar::start_of_cataclysm );
956 } else {
957 ctr = item( "radiocontrol", calendar::start_of_cataclysm );
958 }
960 int power_use = invoke_item( &ctr );
961 mod_power_level( units::from_kilojoule( -power_use ) );
962 bio.powered = ctr.active;
963 } else {
964 bio.powered = g->remoteveh() != nullptr || !get_value( "remote_controlling" ).empty();
965 }
966 } else if( bio.id == bio_plutdump ) {
967 if( query_yn(
968 _( "WARNING: Purging all fuel is likely to result in radiation! Purge anyway?" ) ) ) {
969 add_msg_activate();
971 tank_plut = 0;
972 reactor_plut = 0;
973 } else {
974 refund_power();
975 return false;
976 }
977 } else if( bio.info().is_remote_fueled ) {
978 std::vector<item *> cables = items_with( []( const item & it ) {
979 return it.has_flag( flag_CABLE_SPOOL );
980 } );
981 bool has_cable = !cables.empty();
982 bool free_cable = false;
983 bool success = false;
984 if( !has_cable ) {
986 _( "You need a jumper cable connected to a power source to drain power from it." ) );
987 } else {
988 for( item *cable : cables ) {
989 const std::string state = cable->get_var( "state" );
990 if( state == "cable_charger" ) {
992 _( "Cable is plugged-in to the CBM but it has to be also connected to the power source." ) );
993 }
994 if( state == "cable_charger_link" ) {
995 add_msg_activate();
996 success = true;
998 _( "You are plugged to the vehicle. It will charge you if it has some juice in it." ) );
999 }
1000 if( state == "solar_pack_link" ) {
1001 add_msg_activate();
1002 success = true;
1004 _( "You are plugged to a solar pack. It will charge you if it's unfolded and in sunlight." ) );
1005 }
1006 if( state == "UPS_link" ) {
1007 add_msg_activate();
1008 success = true;
1010 _( "You are plugged to a UPS. It will charge you if it has some juice in it." ) );
1011 }
1012 if( state == "solar_pack" || state == "UPS" ) {
1014 _( "You have a cable plugged to a portable power source, but you need to plug it in to the CBM." ) );
1015 }
1016 if( state == "pay_out_cable" ) {
1018 _( "You have a cable plugged to a vehicle, but you need to plug it in to the CBM." ) );
1019 }
1020 if( state == "attach_first" ) {
1021 free_cable = true;
1022 }
1023 }
1024
1025 if( free_cable ) {
1027 _( "You have at least one free cable in your inventory that you could use to plug yourself in." ) );
1028 }
1029 }
1030 if( !success ) {
1031 refund_power();
1032 bio.powered = false;
1033 return false;
1034 }
1035
1036 } else if( bio.id == bio_probability_travel ) {
1037 if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Tunnel in which direction?" ) ) ) {
1038 if( g->m.impassable( *pnt ) ) {
1039 add_msg_activate();
1040 g->phasing_move( *pnt );
1041 } else {
1042 refund_power();
1043 add_msg_if_player( m_info, _( "There's nothing to phase through there." ) );
1044 return false;
1045 }
1046 } else {
1047 refund_power();
1048 return false;
1049 }
1050 } else {
1051 add_msg_activate();
1052 }
1053
1054 // Recalculate stats (strength, mods from pain etc.) that could have been affected
1056 reset();
1057
1058 // Also reset crafting inventory cache if this bionic spawned a fake item
1059 if( !bio.info().fake_item.is_empty() ) {
1061 }
1062
1063 return true;
1064}
cata::optional< tripoint > choose_adjacent(const std::string &message, const bool allow_vertical)
Request player input of adjacent tile, possibly including vertical tiles.
Definition: action.cpp:1017
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
dealt_projectile_attack projectile_attack(const projectile &proj_arg, const tripoint &source, const tripoint &target_arg, const dispersion_sources &dispersion, Creature *origin, const vehicle *in_veh)
Fires a projectile at the target point from the source point with total_dispersion dispersion.
Definition: ballistics.cpp:202
static const flag_str_id flag_BIONIC_WEAPON("BIONIC_WEAPON")
static const bionic_id bio_cqb("bio_cqb")
static const bionic_id bio_geiger("bio_geiger")
static const itype_id itype_water_clean("water_clean")
static const efftype_id effect_bloodworms("bloodworms")
static const flag_str_id flag_BIONIC_GUN("BIONIC_GUN")
static const efftype_id effect_weed_high("weed_high")
static const efftype_id effect_fungus("fungus")
static const efftype_id effect_pkill_l("pkill_l")
static const efftype_id effect_took_prozac("took_prozac")
static const efftype_id effect_datura("datura")
static const efftype_id effect_drunk("drunk")
static const efftype_id effect_teleglow("teleglow")
static const efftype_id effect_badpoison("badpoison")
static const efftype_id effect_dermatik("dermatik")
static const std::string flag_NO_UNWIELD("NO_UNWIELD")
static const efftype_id effect_pkill2("pkill2")
static const efftype_id effect_adrenaline("adrenaline")
static void force_comedown(effect &eff)
Definition: bionics.cpp:444
static const bionic_id bio_evap("bio_evap")
static const efftype_id effect_took_flumed("took_flumed")
static const bionic_id bio_plutdump("bio_plutdump")
static const efftype_id effect_hallu("hallu")
static const efftype_id effect_pblue("pblue")
static const bionic_id bio_water_extractor("bio_water_extractor")
static const bionic_id bio_hydraulics("bio_hydraulics")
static const efftype_id effect_cocaine_high("cocaine_high")
static const bionic_id bio_lighter("bio_lighter")
static const bionic_id bio_magnet("bio_magnet")
static const efftype_id effect_meth("meth")
static const bionic_id bio_flashbang("bio_flashbang")
static const bionic_id bio_time_freeze("bio_time_freeze")
static const bionic_id bio_meteorologist("bio_meteorologist")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const efftype_id effect_visuals("visuals")
static const bionic_id bio_ears("bio_ears")
static const bionic_id bio_shockwave("bio_shockwave")
static const bionic_id bio_emp("bio_emp")
static const bionic_id bio_remote("bio_remote")
static const efftype_id effect_stung("stung")
static const std::string flag_SEALED("SEALED")
static const flag_str_id flag_BIONIC_TOGGLED("BIONIC_TOGGLED")
static const efftype_id effect_cig("cig")
static const bionic_id bio_tools("bio_tools")
static const bionic_id bio_earplugs("bio_earplugs")
static const bionic_id bio_adrenaline("bio_adrenaline")
static const bionic_id bio_lockpick("bio_lockpick")
static const bionic_id bio_blood_anal("bio_blood_anal")
static const bionic_id bio_probability_travel("bio_probability_travel")
static const bionic_id bio_radscrubber("bio_radscrubber")
static const bionic_id bio_teleport("bio_teleport")
static const efftype_id effect_poison("poison")
static const bionic_id bio_resonator("bio_resonator")
static const bionic_id bio_blood_filter("bio_blood_filter")
static const efftype_id effect_pkill1("pkill1")
static const efftype_id effect_took_xanax("took_xanax")
static const efftype_id effect_pkill3("pkill3")
static const efftype_id effect_took_prozac_bad("took_prozac_bad")
static const bionic_id bio_torsionratchet("bio_torsionratchet")
static const efftype_id effect_iodine("iodine")
static const bionic_id bio_jointservo("bio_jointservo")
int_id< body_part_type > bodypart_id
Definition: bodypart.h:23
units::mass weight_capacity() const override
Definition: character.cpp:2810
void conduct_blood_analysis() const
Definition: character.cpp:2027
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1990
void mod_rad(int mod)
Definition: character.cpp:7200
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1533
bool query_yn(const char *const msg, Args &&... args) const
It is supposed to hide the query_yn to simplify player vs.
Definition: character.h:1437
pimpl< bionic_collection > my_bionics
Definition: character.h:1532
virtual bool invoke_item(item *, const tripoint &pt)
Asks how to use the item (if it has more than one use_method) and uses it.
Definition: character.cpp:7341
void set_power_level(const units::energy &npower)
Definition: character.cpp:1980
void set_painkiller(int npkill)
Sets intensity of painkillers
Definition: character.cpp:9802
bool is_mounted() const
Definition: character.cpp:1143
void apply_damage(Creature *source, bodypart_id hurt, int dam, bool bypass_med=false) override
Actually hurt the player, hurts a body_part directly, no armor reduction.
Definition: character.cpp:8421
bool enough_power_for(const bionic_id &bid) const
Definition: character.cpp:2022
void recalculate_enchantment_cache()
Definition: character.cpp:8000
bool burn_fuel(int b, bool start=false)
Convert fuel to bionic power.
Definition: bionics.cpp:1156
int get_rad() const
Definition: character.cpp:7190
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7380
void reset() override
Handles stat and bonus reset.
Definition: character.cpp:3625
void reset_encumbrance()
Recalculates encumbrance cache.
Definition: character.cpp:3646
units::energy get_power_level() const
Definition: character.cpp:1970
item weapon
Definition: character.h:1529
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6351
void invalidate_crafting_inventory()
Definition: crafting.cpp:590
std::string get_value(const std::string &key) const
Definition: creature.cpp:1341
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1179
bool remove_effect(const efftype_id &eff_id, body_part bp=num_bp)
Removes a listed effect.
Definition: creature.cpp:1136
void mod_moves(int nmoves)
Definition: creature.cpp:1408
const effect & get_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Return the effect that matches the given arguments exactly.
Definition: creature.cpp:1219
virtual avatar * as_avatar()
Definition: creature.h:128
Definition: avatar.h:54
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
iterator begin()
Definition: item_stack.cpp:28
iterator end()
Definition: item_stack.cpp:33
bool active
Definition: item.h:2233
bool is_null() const
Definition: item.cpp:731
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:589
int charges
Definition: item.h:2195
bool has_flag(const std::string &flag) const
Definition: item.cpp:5186
char invlet
Definition: item.h:2232
Definition: map.h:101
iterator erase(const_iterator it) override
Definition: map.cpp:148
bash_results bash(const tripoint &p, int str, bool silent=false, bool destroy=false, bool bash_floor=false, const vehicle *bashing_vehicle=nullptr)
Returns a pair where first is whether anything was smashed and second is if it was destroyed.
Definition: map.cpp:3506
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2288
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5386
tripoint_range< tripoint > points_in_radius(const tripoint &center, size_t radius, size_t radiusz=0) const
Definition: map.cpp:8559
map_stack i_at(const tripoint &p)
Definition: map.cpp:4069
bool is_flammable(const tripoint &p)
Returns true if there is a flammable item or field or the furn/terrain is flammable at p.
Definition: map.cpp:2637
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1004
bool has_items(const tripoint &p) const
Checks for existence of items.
Definition: map.cpp:4750
Simple wrapper to forward functions that may return a cata::optional to vpart_position.
const oter_id & ter(const tripoint_abs_omt &p)
Returns the overmap terrain at the given OMT coordinates.
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:298
uilist: scrolling vertical list menu
Definition: ui.h:187
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:324
const w_point & get_precise() const
Definition: weather.h:218
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
@ m_good
Definition: enums.h:253
@ m_mixed
Definition: enums.h:255
field_type_id fd_fire
Definition: field_type.cpp:345
double get_local_windpower(double windpower, const oter_id &omter, const tripoint &location, const int &winddirection, bool sheltered)
Definition: weather.cpp:938
int get_local_humidity(double humidity, const weather_type_id &weather, bool sheltered)
Definition: weather.cpp:924
std::string print_temperature(double fahrenheit, int decimals)
Print temperature (and convert to Celsius if Celsius display is enabled.)
Definition: weather.cpp:717
std::string get_dirstring(int angle)
Definition: weather.cpp:874
weather_manager & get_weather()
Definition: weather.cpp:64
std::string print_pressure(double pressure, int decimals)
Print pressure (no conversions.)
Definition: weather.cpp:752
std::string print_humidity(double humidity, int decimals)
Print relative humidity (no conversions.)
Definition: weather.cpp:743
int get_local_windchill(double temperature_f, double humidity, double wind_mph)
Definition: weather.cpp:797
constexpr double b
Definition: magic.cpp:1031
string_id< ammo_effect > ammo_effect_str_id
Definition: map.cpp:101
lockpicking_open_result get_lockpicking_open_result(ter_id ter_type, furn_id furn_type)
Gets lockpicked object and message.
Definition: mapdata.cpp:1060
ter_id t_null
Definition: mapdata.cpp:623
furn_id f_null
Definition: mapdata.cpp:1095
void add_msg(std::string msg)
Definition: messages.cpp:884
void fire_wielded_weapon(avatar &you)
Checks if the wielded weapon is a gun and can be fired then starts interactive aiming.
void fire_ranged_bionic(avatar &you, const item &fake_gun, const units::energy &cost_per_shot)
Stores fake gun specified by the bionic and starts interactive aiming.
@ success
Definition: behavior.h:20
const time_point & start_of_cataclysm
Definition: calendar.cpp:33
time_point turn
Definition: calendar.cpp:36
void flashbang(const tripoint &p, bool player_immune, const std::string &exp_name)
Triggers a flashbang explosion at p.
Definition: explosion.cpp:805
void shockwave(const tripoint &p, const shockwave_data &sw, const std::string &exp_name)
Shockwave applies knockback with given parameters to all targets within radius of p.
Definition: explosion.cpp:864
void emp_blast(const tripoint &p)
Triggers an EMP blast at p.
Definition: explosion.cpp:922
bool consume_liquid(item &liquid, const int radius)
Consume / handle as much of the liquid as possible in varying ways.
void sound(const tripoint &p, int vol, sound_t category, const std::string &description, bool ambient=false, const std::string &id="", const std::string &variant="default")
Sound at (p) of intensity (vol)
Definition: sounds.cpp:177
bool teleport(Creature &critter, int min_distance=2, int max_distance=12, bool safe=false, bool add_teleglow=true)
Teleports a creature to a tile within min_distance and max_distance tiles.
Definition: teleport.cpp:24
constexpr value_type to_fahrenheit(const quantity< value_type, temperature_in_millidegree_celsius_tag > &v)
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32
overmapbuffer overmap_buffer
bool one_in(int chance)
Definition: rng.cpp:65
std::string string_format(std::string format, Args &&...args)
Simple wrapper over string_formatter::parse.
std::vector< enchantment_id > enchantments
bionic enchantments
Definition: bionics.h:107
itype_id fake_item
Fake item created for crafting with this bionic available.
Definition: bionics.h:99
units::energy power_activate
Power cost on activation.
Definition: bionics.h:37
int charge_time
How often a bionic draws or produces power while active in turns.
Definition: bionics.h:43
bool is_remote_fueled
This bionic draws power through a cable.
Definition: bionics.h:61
bool has_flag(const flag_str_id &flag) const
Definition: bionics.cpp:244
itype_id ammo_loaded
Definition: bionics.h:155
bool is_auto_start_keep_full() const
Definition: bionics.cpp:2768
bionic_id id
Definition: bionics.h:150
unsigned int ammo_count
Definition: bionics.h:157
bool powered
Definition: bionics.h:153
static damage_instance physical(float bash, float cut, float stab, float arpen=0.0f)
Definition: damage.cpp:27
std::string open_message
Definition: mapdata.h:165
void add_effect(const ammo_effect_str_id &id)
Definition: projectile.h:58
damage_instance impact
Definition: projectile.h:21
bool affects_player
Definition: explosion.h:30
units::temperature temperature
Definition: weather_gen.h:16
double humidity
Definition: weather_gen.h:17
double pressure
Definition: weather_gen.h:18
string_id< material_type > material_id
Definition: type_id.h:85
double convert_velocity(int velocity, const units_type vel_units)
Convert internal velocity units to units defined by user.
const char * velocity_units(const units_type vel_units)
Create a units label for a velocity value.
@ VU_WIND
Definition: units_utility.h:15

References _, item::active, sounds::activity, projectile::add_effect(), Creature::add_effect(), map::add_field(), map::add_item_or_charges(), add_msg(), Creature::add_msg_if_player(), shockwave_data::affects_player, bionic::ammo_count, bionic::ammo_loaded, item::ammo_set(), apply_damage(), Creature::as_avatar(), b, map::bash(), item_stack::begin(), bio_adrenaline, bio_blood_anal, bio_blood_filter, bio_cqb, bio_earplugs, bio_ears, bio_emp, bio_evap, bio_flashbang, bio_geiger, bio_hydraulics, bio_jointservo, bio_lighter, bio_lockpick, bio_magnet, bio_meteorologist, bio_plutdump, bio_probability_travel, bio_radscrubber, bio_remote, bio_resonator, bio_shockwave, bio_teleport, bio_time_freeze, bio_tools, bio_torsionratchet, bio_water_extractor, burn_fuel(), bionic_data::charge_time, bionic::charge_timer, item::charges, choose_adjacent(), colorize(), sounds::combat, conduct_blood_analysis(), liquid_handler::consume_liquid(), convert_velocity(), shockwave_data::dam_mult, dispose_item(), effect_adrenaline, effect_badpoison, effect_bloodworms, effect_cig, effect_cocaine_high, effect_datura, effect_dermatik, effect_drunk, effect_fungus, effect_hallu, effect_iodine, effect_meth, effect_pblue, effect_pkill1, effect_pkill2, effect_pkill3, effect_pkill_l, effect_poison, effect_stung, effect_teleglow, effect_took_flumed, effect_took_prozac, effect_took_prozac_bad, effect_took_xanax, effect_visuals, effect_weed_high, explosion_handler::emp_blast(), bionic_data::enchantments, item_stack::end(), dealt_projectile_attack::end_point, enough_power_for(), map_stack::erase(), f_null, bionic_data::fake_item, fd_fire, avatar_action::fire_ranged_bionic(), avatar_action::fire_wielded_weapon(), flag_BIONIC_GUN, flag_BIONIC_TOGGLED, flag_BIONIC_WEAPON, flag_CABLE_SPOOL(), flag_NO_UNWIELD(), flag_SEALED(), explosion_handler::flashbang(), shockwave_data::force, force_comedown(), units::from_kilojoule(), g, get_dirstring(), Creature::get_effect(), get_local_humidity(), get_local_windchill(), get_local_windpower(), get_lockpicking_open_result(), get_map(), get_power_level(), weather_manager::get_precise(), get_rad(), Creature::get_value(), get_weather(), global_omt_location(), has_active_bionic(), Creature::has_effect(), bionic_data::has_flag(), item::has_flag(), map::has_flag(), map::has_items(), w_point::humidity, map::i_at(), bionic::id, projectile::impact, bionic::incapacitated_time, bionic::info(), invalidate_crafting_inventory(), item::invlet, invoke_item(), bionic::is_auto_start_keep_full(), string_id< T >::is_empty(), map::is_flammable(), is_mounted(), item::is_null(), bionic_data::is_remote_fueled, visitable< Character >::items_with(), itype_water_clean, m_bad, m_good, m_info, m_mixed, m_neutral, martial_arts_data, Creature::mod_moves(), mod_power_level(), mod_rad(), my_bionics, bionic_data::name, lockpicking_open_result::new_furn_type, lockpicking_open_result::new_ter_type, one_in(), lockpicking_open_result::open_message, overmap_buffer, damage_instance::physical(), map::points_in_radius(), pos(), bionic_data::power_activate, bionic::powered, w_point::pressure, print_humidity(), print_pressure(), print_temperature(), projectile_attack(), query_yn(), shockwave_data::radius, projectile::range, reactor_plut, recalculate_enchantment_cache(), Creature::remove_effect(), reset(), reset_encumbrance(), rl_dist(), rng(), set_painkiller(), set_power_level(), set_rad(), set_stim(), explosion_handler::shockwave(), slow_rad, sounds::sound(), projectile::speed, calendar::start_of_cataclysm, string_format(), shockwave_data::stun, behavior::success, t_null, tank_plut, teleport::teleport(), w_point::temperature, overmapbuffer::ter(), item::tname(), units::to_fahrenheit(), units::to_kilojoule(), calendar::turn, map::veh_at(), velocity_units(), VU_WIND, weapon, and weight_capacity().

Referenced by npc::activate_bionic_by_id(), add_bionic(), player::power_bionics(), and npc::use_bionic_by_id().

◆ activate_mutation()

void Character::activate_mutation ( const trait_id mutation)

Definition at line 470 of file mutation.cpp.

471{
472 const mutation_branch &mdata = mut.obj();
473 trait_data &tdata = my_mutations[mut];
474 // You can take yourself halfway to Near Death levels of hunger/thirst.
475 // Fatigue can go to Exhausted.
476 if( !can_use_mutation_warn( mut, *this ) ) {
477 return;
478 }
480 tdata.powered = true;
481
482 if( !mut->enchantments.empty() ) {
484 }
485
486 if( mdata.transform ) {
487 const cata::value_ptr<mut_transform> trans = mdata.transform;
488 mod_moves( - trans->moves );
489 switch_mutations( mut, trans->target, trans->active );
490 return;
491 }
492
493 if( mut == trait_WEB_WEAVER ) {
494 g->m.add_field( pos(), fd_web, 1 );
495 add_msg_if_player( _( "You start spinning web with your spinnerets!" ) );
496 } else if( mut == trait_BURROW ) {
497 tdata.powered = false;
498 item burrowing_item( itype_id( "fake_burrowing" ) );
499 invoke_item( &burrowing_item );
500 return; // handled when the activity finishes
501 } else if( mut == trait_SLIMESPAWNER ) {
502 monster *const slime = g->place_critter_around( mtype_id( "mon_player_blob" ), pos(), 1 );
503 if( !slime ) {
504 // Oops, no room to divide!
505 add_msg_if_player( m_bad, _( "You focus, but are too hemmed in to birth a new slimespring!" ) );
506 tdata.powered = false;
507 return;
508 }
510 _( "You focus, and with a pleasant splitting feeling, birth a new slimespring!" ) );
511 slime->friendly = -1;
512 if( one_in( 3 ) ) {
514 //~ Usual enthusiastic slimespring small voices! :D
515 _( "wow! you look just like me! we should look out for each other!" ) );
516 } else if( one_in( 2 ) ) {
517 //~ Usual enthusiastic slimespring small voices! :D
518 add_msg_if_player( m_good, _( "come on, big me, let's go!" ) );
519 } else {
520 //~ Usual enthusiastic slimespring small voices! :D
521 add_msg_if_player( m_good, _( "we're a team, we've got this!" ) );
522 }
523 tdata.powered = false;
524 return;
525 } else if( mut == trait_NAUSEA || mut == trait_VOMITOUS ) {
526 vomit();
527 tdata.powered = false;
528 return;
529 } else if( mut == trait_M_FERTILE ) {
530 spores();
531 tdata.powered = false;
532 return;
533 } else if( mut == trait_M_BLOOM ) {
534 blossoms();
535 tdata.powered = false;
536 return;
537 } else if( mut == trait_M_PROVENANCE ) {
538 spores(); // double trouble!
539 blossoms();
540 tdata.powered = false;
541 return;
542 } else if( mut == trait_SELFAWARE ) {
543 print_health();
544 tdata.powered = false;
545 return;
546 } else if( mut == trait_TREE_COMMUNION ) {
547 tdata.powered = false;
548 if( !overmap_buffer.ter( global_omt_location() ).obj().is_wooded() ) {
549 add_msg_if_player( m_info, _( "You can only do that in a wooded area." ) );
550 return;
551 }
552 // Check for adjacent trees.
553 bool adjacent_tree = false;
554 for( const tripoint &p2 : g->m.points_in_radius( pos(), 1 ) ) {
555 if( g->m.has_flag( "TREE", p2 ) ) {
556 adjacent_tree = true;
557 }
558 }
559 if( !adjacent_tree ) {
560 add_msg_if_player( m_info, _( "You can only do that next to a tree." ) );
561 return;
562 }
563
565 add_msg_if_player( _( "You reach out to the trees with your roots." ) );
566 } else {
568 _( "You lay next to the trees letting your hair roots tangle with the trees." ) );
569 }
570
572
574 const time_duration startup_time = has_trait( trait_ROOTS3 ) ? rng( 15_minutes,
575 30_minutes ) : rng( 60_minutes, 90_minutes );
576 activity.values.push_back( to_turns<int>( startup_time ) );
577 return;
578 } else {
579 const time_duration startup_time = rng( 120_minutes, 180_minutes );
580 activity.values.push_back( to_turns<int>( startup_time ) );
581 return;
582 }
583 } else if( mut == trait_DEBUG_BIONIC_POWER ) {
584 mod_max_power_level( 100_kJ );
585 add_msg_if_player( m_good, _( "Bionic power storage increased by 100." ) );
586 tdata.powered = false;
587 return;
588 } else if( mut == trait_DEBUG_BIONIC_POWERGEN ) {
589 int npower;
590 if( query_int( npower, "Modify bionic power by how much? (Values are in joules)" ) ) {
592 add_msg_if_player( m_good, "Bionic power increased by %dJ.", npower );
593 tdata.powered = false;
594 }
595 return;
596 } else if( !mdata.spawn_item.is_empty() ) {
597 item tmpitem( mdata.spawn_item );
598 i_add_or_drop( tmpitem );
600 tdata.powered = false;
601 return;
602 } else if( !mdata.ranged_mutation.is_empty() ) {
605 tdata.powered = false;
606 return;
607 }
608}
player_activity activity
Definition: character.h:1524
void mod_max_power_level(const units::energy &npower_max)
Definition: character.cpp:2002
void vomit()
Handles Character vomiting effects.
Definition: character.cpp:7808
void print_health() const
Definition: character.cpp:4211
void blossoms()
Definition: character.cpp:8804
void switch_mutations(const trait_id &switched, const trait_id &target, bool start_powered)
Unset switched mutation and set target mutation instead.
Definition: mutation.cpp:184
void spores()
Definition: character.cpp:8790
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2462
std::unordered_map< trait_id, trait_data > my_mutations
Traits / mutations of the character.
Definition: character.h:2091
void mutation_spend_resources(const trait_id &mut)
Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated...
Definition: mutation.cpp:1723
void assign_activity(const activity_id &type, int moves=calendar::INDEFINITELY_LONG, int index=-1, int pos=INT_MIN, const std::string &name="")
Legacy activity assignment, does not work for any activites using the new activity_actor class and ma...
Definition: character.cpp:9203
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
int friendly
Definition: monster.h:473
std::vector< int > values
A duration defined as a number of specific time units.
Definition: calendar.h:180
field_type_id fd_web
Definition: field_type.cpp:340
static const activity_id ACT_TREE_COMMUNION("ACT_TREE_COMMUNION")
static const trait_id trait_M_FERTILE("M_FERTILE")
static const trait_id trait_BURROW("BURROW")
static const trait_id trait_SLIMESPAWNER("SLIMESPAWNER")
static const trait_id trait_ROOTS2("ROOTS2")
static const trait_id trait_WEB_WEAVER("WEB_WEAVER")
bool can_use_mutation_warn(const trait_id &mut, const Character &character)
Calls can_use_mutation and if it fails, print a standard message.
Definition: mutation.cpp:1712
static const trait_id trait_M_BLOOM("M_BLOOM")
static const trait_id trait_VOMITOUS("VOMITOUS")
static const trait_id trait_SELFAWARE("SELFAWARE")
static const trait_id trait_DEBUG_BIONIC_POWERGEN("DEBUG_BIONIC_POWERGEN")
static const trait_id trait_NAUSEA("NAUSEA")
static const trait_id trait_M_PROVENANCE("M_PROVENANCE")
static const trait_id trait_TREE_COMMUNION("TREE_COMMUNION")
static const trait_id trait_DEBUG_BIONIC_POWER("DEBUG_BIONIC_POWER")
static const trait_id trait_ROOTS3("ROOTS3")
void fire_ranged_mutation(avatar &you, const item &fake_gun)
Stores fake gun specified by the mutation and starts interactive aiming.
constexpr quantity< value_type, energy_in_joule_tag > from_joule(const value_type v)
Definition: units_energy.h:25
bool query_int(int &result, int default_val, const std::string &text)
Definition: output.cpp:718
std::string ranged_mutation_message() const
std::string spawn_item_message() const
cata::value_ptr< mut_transform > transform
Definition: mutation.h:151
itype_id spawn_item
The item, if any, spawned by the mutation.
Definition: mutation.h:203
itype_id ranged_mutation
The fake gun, if any, spawned and fired by the ranged mutation.
Definition: mutation.h:241

References _, ACT_TREE_COMMUNION, activity, Creature::add_msg_if_player(), assign_activity(), blossoms(), can_use_mutation_warn(), mutation_branch::enchantments, fd_web, avatar_action::fire_ranged_mutation(), monster::friendly, units::from_joule(), g, global_omt_location(), has_trait(), i_add_or_drop(), invoke_item(), string_id< T >::is_empty(), itype_id, m_bad, m_good, m_info, mod_max_power_level(), Creature::mod_moves(), mod_power_level(), mtype_id, mutation_spend_resources(), my_mutations, string_id< T >::obj(), one_in(), overmap_buffer, pos(), Character::trait_data::powered, print_health(), query_int(), mutation_branch::ranged_mutation, mutation_branch::ranged_mutation_message(), recalculate_enchantment_cache(), rng(), mutation_branch::spawn_item, mutation_branch::spawn_item_message(), spores(), switch_mutations(), overmapbuffer::ter(), trait_BURROW, trait_DEBUG_BIONIC_POWER, trait_DEBUG_BIONIC_POWERGEN, trait_M_BLOOM, trait_M_FERTILE, trait_M_PROVENANCE, trait_NAUSEA, trait_ROOTS2, trait_ROOTS3, trait_SELFAWARE, trait_SLIMESPAWNER, trait_TREE_COMMUNION, trait_VOMITOUS, trait_WEB_WEAVER, mutation_branch::transform, player_activity::values, and vomit().

Referenced by player::power_mutations(), and player::power_mutations_ui().

◆ active_light()

float Character::active_light ( ) const

Returns character luminosity based on the brightest active item they are carrying.

Definition at line 6392 of file character.cpp.

6393{
6394 float lumination = 0;
6395
6396 int maxlum = 0;
6397 has_item_with( [&maxlum]( const item & it ) {
6398 const int lumit = it.getlight_emit();
6399 if( maxlum < lumit ) {
6400 maxlum = lumit;
6401 }
6402 return false; // continue search, otherwise has_item_with would cancel the search
6403 } );
6404
6405 lumination = static_cast<float>( maxlum );
6406
6407 float mut_lum = 0.0f;
6408 for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
6409 if( mut.second.powered ) {
6410 float curr_lum = 0.0f;
6411 for( const auto elem : mut.first->lumination ) {
6412 int coverage = 0;
6413 for( const item &i : worn ) {
6414 if( i.covers( elem.first ) && !i.has_flag( flag_ALLOWS_NATURAL_ATTACKS ) &&
6415 !i.has_flag( flag_SEMITANGIBLE ) &&
6416 !i.has_flag( flag_PERSONAL ) && !i.has_flag( flag_AURA ) ) {
6417 coverage += i.get_coverage();
6418 }
6419 }
6420 curr_lum += elem.second * ( 1 - ( coverage / 100.0f ) );
6421 }
6422 mut_lum += curr_lum;
6423 }
6424 }
6425
6426 lumination = std::max( lumination, mut_lum );
6427
6428 if( lumination < 60 && has_active_bionic( bio_flashlight ) ) {
6429 lumination = 60;
6430 } else if( lumination < 25 && has_artifact_with( AEP_GLOW ) ) {
6431 lumination = 25;
6432 } else if( lumination < 5 && ( has_effect( effect_glowing ) ||
6434 has_effect( effect_glowy_led ) ) ) ) {
6435 lumination = 5;
6436 }
6437 return lumination;
6438}
static const efftype_id effect_glowy_led("glowy_led")
static const bionic_id bio_flashlight("bio_flashlight")
static const std::string flag_SEMITANGIBLE("SEMITANGIBLE")
static const std::string flag_ALLOWS_NATURAL_ATTACKS("ALLOWS_NATURAL_ATTACKS")
static const efftype_id effect_glowing("glowing")
static const std::string flag_AURA("AURA")
static const bionic_id bio_tattoo_led("bio_tattoo_led")
static const std::string flag_PERSONAL("PERSONAL")
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3223
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8217
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:104
@ AEP_GLOW
Definition: enums.h:115

References AEP_GLOW, bio_flashlight, bio_tattoo_led, effect_glowing, effect_glowy_led, flag_ALLOWS_NATURAL_ATTACKS(), flag_AURA(), flag_PERSONAL(), flag_SEMITANGIBLE(), item::getlight_emit(), has_active_bionic(), has_artifact_with(), Creature::has_effect(), visitable< Character >::has_item_with(), my_mutations, and worn.

Referenced by map::apply_character_light(), and player::fine_detail_vision_mod().

◆ add_addiction()

void Character::add_addiction ( add_type  type,
int  strength 
)

Adds an addiction to the player.

Definition at line 1890 of file suffer.cpp.

1891{
1892 if( type == add_type::NONE ) {
1893 return;
1894 }
1895 time_duration timer = 2_hours;
1896 if( has_trait( trait_ADDICTIVE ) ) {
1897 strength *= 2;
1898 timer = 1_hours;
1899 } else if( has_trait( trait_NONADDICTIVE ) ) {
1900 strength /= 2;
1901 timer = 6_hours;
1902 }
1903 //Update existing addiction
1904 for( auto &i : addictions ) {
1905 if( i.type != type ) {
1906 continue;
1907 }
1908
1909 if( i.sated < 0_turns ) {
1910 i.sated = timer;
1911 } else if( i.sated < 10_minutes ) {
1912 // TODO: Make this variable?
1913 i.sated += timer;
1914 } else {
1915 i.sated += timer / 2;
1916 }
1917 if( i.intensity < MAX_ADDICTION_LEVEL && strength > i.intensity * rng( 2, 5 ) ) {
1918 i.intensity++;
1919 }
1920
1921 add_msg( m_debug, "Updating addiction: %d intensity, %d sated",
1922 i.intensity, to_turns<int>( i.sated ) );
1923
1924 return;
1925 }
1926
1927 // Add a new addiction
1928 const int roll = rng( 0, 100 );
1929 add_msg( m_debug, "Addiction: roll %d vs strength %d", roll, strength );
1930 if( roll < strength ) {
1931 const std::string &type_name = addiction_type_name( type );
1932 add_msg( m_debug, "%s got addicted to %s", disp_name(), type_name );
1933 addictions.emplace_back( type, 1 );
1934 g->events().send<event_type::gains_addiction>( getID(), type );
1935 }
1936}
std::string addiction_type_name(add_type const cur)
Returns the name of an addiction.
Definition: addiction.cpp:253
constexpr int MAX_ADDICTION_LEVEL
Definition: addiction.h:14
std::string disp_name(bool possessive=false, bool capitalize_first=false) const override
Returns either "you" or the player's name.
Definition: character.cpp:546
std::vector< addiction > addictions
Definition: character.h:1554
character_id getID() const
Definition: character.cpp:477
@ m_debug
Definition: enums.h:264
@ type
Definition: enums.h:75
static const trait_id trait_NONADDICTIVE("NONADDICTIVE")
static const trait_id trait_ADDICTIVE("ADDICTIVE")

References add_msg(), addiction_type_name(), addictions, disp_name(), g, gains_addiction, getID(), has_trait(), m_debug, MAX_ADDICTION_LEVEL, NONE, rng(), trait_ADDICTIVE, trait_NONADDICTIVE, and type.

Referenced by iexamine::flower_poppy(), marloss_common(), and modify_addiction().

◆ add_bionic()

void Character::add_bionic ( const bionic_id b)

Adds a bionic to my_bionics[].

Definition at line 2532 of file bionics.cpp.

2533{
2534 if( has_bionic( b ) ) {
2535 debugmsg( "Tried to install bionic %s that is already installed!", b.c_str() );
2536 return;
2537 }
2538
2539 const units::energy pow_up = b->capacity;
2540 mod_max_power_level( pow_up );
2542 add_msg_if_player( m_good, _( "Increased storage capacity by %i." ),
2543 units::to_kilojoule( pow_up ) );
2544 // Power Storage CBMs are not real bionic units, so return without adding it to my_bionics
2545 return;
2546 }
2547
2548 my_bionics->push_back( bionic( b, get_free_invlet( *this->as_player() ) ) );
2549 if( b == bio_tools || b == bio_ears ) {
2550 activate_bionic( my_bionics->size() - 1 );
2551 }
2552
2553 for( const bionic_id &inc_bid : b->included_bionics ) {
2554 add_bionic( inc_bid );
2555 }
2556
2557 for( const std::pair<const spell_id, int> &spell_pair : b->learned_spells ) {
2558 const spell_id learned_spell = spell_pair.first;
2559 if( learned_spell->spell_class != trait_id( "NONE" ) ) {
2560 const trait_id spell_class = learned_spell->spell_class;
2561 // spells you learn from a bionic overwrite the opposite spell class.
2562 // for best UX, include those spell classes in "canceled_mutations"
2563 if( !has_trait( spell_class ) ) {
2564 set_mutation( spell_class );
2565 on_mutation_gain( spell_class );
2566 add_msg_if_player( spell_class->desc() );
2567 }
2568 }
2569 if( !magic->knows_spell( learned_spell ) ) {
2570 magic->learn_spell( learned_spell, *this, true );
2571 }
2572 spell &known_spell = magic->get_spell( learned_spell );
2573 // spells you learn from installing a bionic upgrade spells you know if they are the same
2574 if( known_spell.get_level() < spell_pair.second ) {
2575 known_spell.set_level( spell_pair.second );
2576 }
2577 }
2578
2581 if( !b->enchantments.empty() ) {
2583 }
2584}
static const bionic_id bio_power_storage("bio_power_storage")
static const bionic_id bio_power_storage_mkII("bio_power_storage_mkII")
char get_free_invlet(player &p)
Definition: bionics_ui.cpp:176
void on_mutation_gain(const trait_id &mid)
Called when a mutation is gained.
Definition: character.cpp:9904
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1880
bool activate_bionic(int b, bool eff_only=false)
Handles bionic activation effects of the entered bionic, returns if anything activated.
Definition: bionics.cpp:532
void add_bionic(const bionic_id &b)
Adds a bionic to my_bionics[].
Definition: bionics.cpp:2532
void recalc_sight_limits()
Modifies the player's sight values Must be called when any of the following change: This must be call...
Definition: character.cpp:1706
void set_mutation(const trait_id &)
Add or removes a mutation on the player, but does not trigger mutation loss/gain effects.
Definition: mutation.cpp:154
pimpl< known_magic > magic
Definition: character.h:1420
virtual player * as_player()
Definition: creature.h:122
trait_id spell_class
Definition: magic.h:236
Definition: magic.h:286
int get_level() const
Definition: magic.cpp:1034
void set_level(int nlevel)
Definition: magic.cpp:612
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
std::string desc() const

References _, activate_bionic(), add_bionic(), Creature::add_msg_if_player(), Creature::as_player(), b, bio_ears, bio_power_storage, bio_power_storage_mkII, bio_tools, debugmsg, mutation_branch::desc(), get_free_invlet(), spell::get_level(), has_bionic(), has_trait(), m_good, magic, mod_max_power_level(), my_bionics, on_mutation_gain(), recalc_sight_limits(), recalculate_enchantment_cache(), reset_encumbrance(), spell::set_level(), set_mutation(), spell_type::spell_class, and units::to_kilojoule().

Referenced by add_bionic(), bionics_install_failure(), avatar::create(), deactivate_bionic(), player::load(), perform_install(), and npc::randomize().

◆ add_known_trap()

void Character::add_known_trap ( const tripoint pos,
const trap t 
)

Definition at line 10261 of file character.cpp.

10262{
10263 const tripoint p = get_map().getabs( pos );
10264 if( t.is_null() ) {
10265 known_traps.erase( p );
10266 } else {
10267 // TODO: known_traps should map to a trap_str_id
10268 known_traps[p] = t.id.str();
10269 }
10270}
trap_map known_traps
Definition: character.h:2077
tripoint getabs(const tripoint &p) const
Translates local (to this map) coordinates of a square to global absolute coordinates.
Definition: map.cpp:8215
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
bool is_null() const
Whether this is the null-traps, aka no trap at all.
Definition: trap.cpp:245
trap_str_id id
Definition: trap.h:87

References get_map(), map::getabs(), trap::id, trap::is_null(), known_traps, pos(), and string_id< T >::str().

Referenced by vehicle::handle_trap(), place_and_add_as_known(), and player::search_surroundings().

◆ add_miss_reason()

void Character::add_miss_reason ( const std::string &  reason,
unsigned int  weight 
)

Adds a reason for why the player would miss a melee attack.

To possibly be messaged to the player when he misses a melee attack.

Parameters
reasonA message for the player that gives a reason for him missing.
weightThe weight used when choosing what reason to pick when the player misses.

Definition at line 318 of file melee.cpp.

319{
320 melee_miss_reasons.add( reason, weight );
321
322}
struct weighted_int_list< std::string > melee_miss_reasons
Definition: character.h:2199

References melee_miss_reasons.

Referenced by temperature_effect::apply(), eff_fun_hallu(), get_miss_reason(), player::hardcoded_effects(), player::process_one_effect(), player::reset_stats(), and suffer_in_sunlight().

◆ add_morale()

void Character::add_morale ( const morale_type type,
int  bonus,
int  max_bonus = 0,
const time_duration duration = 1_hours,
const time_duration decay_start = 30_minutes,
bool  capped = false,
const itype item_type = nullptr 
)

Definition at line 9105 of file character.cpp.

9108{
9109 if( item_type != nullptr ) {
9110 morale->add( type, bonus, max_bonus, duration, decay_start, capped, *item_type );
9111 } else {
9112 morale->add( type, bonus, max_bonus, duration, decay_start, capped );
9113 }
9114}
pimpl< player_morale > morale
Definition: character.h:2136

References morale, and type.

Referenced by addict_effect(), apply_persistent_morale(), apply_wetness_morale(), iuse::artifact(), iuse::bell(), iuse::blech(), debug_menu::character_edit_menu(), iuse::datura(), monster::die(), avatar::do_read(), iuse::einktabletpc(), npc::finish_read(), player::fire_gun(), activity_handlers::generic_game_do_turn(), activity_handlers::haircut_finish(), marloss_add(), marloss_common(), activity_handlers::meditate_finish(), modify_morale(), spell_effect::morale(), iuse::mycus(), iuse::plantblech(), iuse::play_music(), activity_handlers::play_with_pet_finish(), iuse::portable_game(), game::process_artifact(), process_bionic(), firestarter_actor::resolve_firestarter_use(), set_up_butchery_activity(), activity_handlers::shaving_finish(), game::start_game(), suffer_from_chemimbalance(), suffer_from_other_mutations(), suffer_from_schizophrenia(), suffer_while_awake(), activity_handlers::tree_communion_do_turn(), update_bodytemp(), enzlave_actor::use(), musical_instrument_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), activity_handlers::vibe_do_turn(), activity_handlers::vibe_finish(), and avatar::vomit().

◆ add_traits() [1/2]

void Character::add_traits ( )

Adds mandatory scenario and profession traits unless you already have them And if you do already have them, refunds the points for the trait.

Definition at line 2858 of file newcharacter.cpp.

2859{
2860 points_left points = points_left();
2861 add_traits( points );
2862}
void add_traits()
Adds mandatory scenario and profession traits unless you already have them And if you do already have...

References add_traits().

Referenced by add_traits(), avatar::randomize(), reset_scenario(), and set_profession().

◆ add_traits() [2/2]

void Character::add_traits ( points_left points)

Definition at line 2864 of file newcharacter.cpp.

2865{
2866 // TODO: get rid of using g->u here, use `this` instead
2867 for( const trait_id &tr : g->u.prof->get_locked_traits() ) {
2868 if( !has_trait( tr ) ) {
2869 toggle_trait( tr );
2870 } else {
2871 points.trait_points += tr->points;
2872 }
2873 }
2874 for( const trait_id &tr : g->scen->get_locked_traits() ) {
2875 if( !has_trait( tr ) ) {
2876 toggle_trait( tr );
2877 }
2878 }
2879}
void toggle_trait(const trait_id &)
Toggles a trait on the player and in their mutation list.
Definition: mutation.cpp:127
int trait_points
Definition: newcharacter.h:9

References g, has_trait(), toggle_trait(), and points_left::trait_points.

◆ addiction_level()

int Character::addiction_level ( add_type  type) const

Returns the intensity of the specified addiction.

Definition at line 1959 of file suffer.cpp.

1960{
1961 auto iter = std::find_if( addictions.begin(), addictions.end(),
1962 [type]( const addiction & ad ) {
1963 return ad.type == type;
1964 } );
1965 return iter != addictions.end() ? iter->intensity : 0;
1966}

References addictions, and type.

Referenced by iuse::ecig(), mend(), player::process_one_effect(), and iuse::smoking().

◆ adjacent_tile()

tripoint Character::adjacent_tile ( ) const

Returns an unoccupied, safe adjacent point.

If none exists, returns player position.

Definition at line 7856 of file character.cpp.

7857{
7858 std::vector<tripoint> ret;
7859 int dangerous_fields = 0;
7860 map &here = get_map();
7861 for( const tripoint &p : here.points_in_radius( pos(), 1 ) ) {
7862 if( p == pos() ) {
7863 // Don't consider player position
7864 continue;
7865 }
7866 const trap &curtrap = here.tr_at( p );
7867 if( g->critter_at( p ) == nullptr && here.passable( p ) &&
7868 ( curtrap.is_null() || curtrap.is_benign() ) ) {
7869 // Only consider tile if unoccupied, passable and has no traps
7870 dangerous_fields = 0;
7871 auto &tmpfld = here.field_at( p );
7872 for( auto &fld : tmpfld ) {
7873 const field_entry &cur = fld.second;
7874 if( cur.is_dangerous() ) {
7875 dangerous_fields++;
7876 }
7877 }
7878
7879 if( dangerous_fields == 0 && ! get_map().obstructed_by_vehicle_rotation( pos(), p ) ) {
7880 ret.push_back( p );
7881 }
7882 }
7883 }
7884
7885 return random_entry( ret, pos() ); // player position if no valid adjacent tiles
7886}
An active or passive effect existing on a tile.
Definition: field.h:20
bool is_dangerous() const
Definition: field.h:78
const trap & tr_at(const tripoint &p) const
Definition: map.cpp:5115
const field & field_at(const tripoint &p) const
Get the fields that are here.
Definition: map.cpp:5277
bool passable(const tripoint &p) const
Definition: map.cpp:1795
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88
Definition: trap.h:86
bool is_benign() const
If true, this is not really a trap and there won't be any safety queries before stepping onto it (e....
Definition: trap.h:159

References map::field_at(), g, get_map(), trap::is_benign(), field_entry::is_dangerous(), trap::is_null(), map::passable(), map::points_in_radius(), pos(), random_entry(), cata::hash64_detail::ret, and map::tr_at().

Referenced by player::uncanny_dodge(), and vomit().

◆ adjust_for_focus()

int Character::adjust_for_focus ( int  amount) const

Definition at line 9942 of file character.cpp.

9943{
9944 int effective_focus = focus_pool;
9945 if( has_trait( trait_FASTLEARNER ) ) {
9946 effective_focus += 15;
9947 }
9948 if( has_active_bionic( bio_memory ) ) {
9949 effective_focus += 10;
9950 }
9951 if( has_trait( trait_SLOWLEARNER ) ) {
9952 effective_focus -= 15;
9953 }
9954 effective_focus += ( get_int() - get_option<int>( "INT_BASED_LEARNING_BASE_VALUE" ) ) *
9955 get_option<int>( "INT_BASED_LEARNING_FOCUS_ADJUSTMENT" );
9956 double tmp = amount * ( effective_focus / 100.0 );
9957 return roll_remainder( tmp );
9958}
static const trait_id trait_FASTLEARNER("FASTLEARNER")
static const bionic_id bio_memory("bio_memory")
static const trait_id trait_SLOWLEARNER("SLOWLEARNER")
int focus_pool
Definition: character.h:1543
virtual int get_int() const
Definition: character.cpp:4092

References bio_memory, focus_pool, get_int(), has_active_bionic(), has_trait(), roll_remainder(), trait_FASTLEARNER, and trait_SLOWLEARNER.

Referenced by spell::casting_exp(), avatar::do_read(), and player::practice().

◆ age()

int Character::age ( ) const

Definition at line 6915 of file character.cpp.

6916{
6917 int years_since_cataclysm = to_turns<int>( calendar::turn - calendar::turn_zero ) /
6918 to_turns<int>( calendar::year_length() );
6919 return init_age + years_since_cataclysm;
6920}
int init_age
age in years at character creation
Definition: character.h:2071
time_duration year_length()
Definition: calendar.cpp:461
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26

References init_age, calendar::turn, calendar::turn_zero, and calendar::year_length().

Referenced by age_string(), player_morale::morale_point::deserialize(), submap::load(), player_morale::morale_point::serialize(), and set_base_age().

◆ age_string()

std::string Character::age_string ( ) const

Definition at line 6922 of file character.cpp.

6923{
6924 //~ how old the character is in years. try to limit number of characters to fit on the screen
6925 std::string unformatted = _( "%d years" );
6926 return string_format( unformatted, age() );
6927}
int age() const
Definition: character.cpp:6915

References _, age(), and string_format().

Referenced by draw_stats_info(), and draw_stats_tab().

◆ aim_cap_from_volume()

double Character::aim_cap_from_volume ( const item gun) const

Definition at line 644 of file character.cpp.

645{
646 skill_id gun_skill = gun.gun_skill();
647 double aim_cap = std::min( 49.0, 49.0 - static_cast<float>( gun.volume() / 75_ml ) );
648 // TODO: also scale with skill level.
649 if( gun_skill == skill_smg ) {
650 aim_cap = std::max( 12.0, aim_cap );
651 } else if( gun_skill == skill_shotgun ) {
652 aim_cap = std::max( 12.0, aim_cap );
653 } else if( gun_skill == skill_pistol ) {
654 aim_cap = std::max( 15.0, aim_cap * 1.25 );
655 } else if( gun_skill == skill_rifle ) {
656 aim_cap = std::max( 7.0, aim_cap - 5.0 );
657 } else if( gun_skill == skill_archery ) {
658 aim_cap = std::max( 13.0, aim_cap );
659 } else { // Launchers, etc.
660 aim_cap = std::max( 10.0, aim_cap );
661 }
662 return aim_cap;
663}
static const skill_id skill_shotgun("shotgun")
static const skill_id skill_archery("archery")
static const skill_id skill_smg("smg")
static const skill_id skill_rifle("rifle")
static const skill_id skill_pistol("pistol")
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7020
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:4985

References item::gun_skill(), skill_archery, skill_pistol, skill_rifle, skill_shotgun, skill_smg, and item::volume().

Referenced by aim_per_move().

◆ aim_per_move()

double Character::aim_per_move ( const item gun,
double  recoil 
) const
Dexterity increases aiming speed

Definition at line 665 of file character.cpp.

666{
667 if( !gun.is_gun() ) {
668 return 0.0;
669 }
670
671 std::pair<int, int> best_sight = get_fastest_sight( gun, recoil );
672 int sight_speed_modifier = best_sight.first;
673 int limit = best_sight.second;
674 if( sight_speed_modifier == INT_MIN ) {
675 // No suitable sights (already at maximum aim).
676 return 0;
677 }
678
679 // Overall strategy for determining aim speed is to sum the factors that contribute to it,
680 // then scale that speed by current recoil level.
681 // Player capabilities make aiming faster, and aim speed slows down as it approaches 0.
682 // Base speed is non-zero to prevent extreme rate changes as aim speed approaches 0.
683 double aim_speed = 10.0;
684
685 skill_id gun_skill = gun.gun_skill();
686 // Ranges [0 - 10]
687 aim_speed += aim_speed_skill_modifier( gun_skill );
688
689 // Range [0 - 12]
690 /** @EFFECT_DEX increases aiming speed */
691 aim_speed += aim_speed_dex_modifier();
692
693 // Range [0 - 10]
694 aim_speed += sight_speed_modifier;
695
696 // Each 5 points (combined) of hand encumbrance decreases aim speed by one unit.
697 aim_speed -= aim_speed_encumbrance_modifier();
698
699 aim_speed = std::min( aim_speed, aim_cap_from_volume( gun ) );
700
701 // Just a raw scaling factor.
702 aim_speed *= 6.5;
703
704 // Scale rate logistically as recoil goes from MAX_RECOIL to 0.
705 aim_speed *= 1.0 - logarithmic_range( 0, MAX_RECOIL, recoil );
706
707 // Minimum improvement is 5MoA. This mostly puts a cap on how long aiming for sniping takes.
708 aim_speed = std::max( aim_speed, 5.0 );
709
710 // Never improve by more than the currently used sights permit.
711 return std::min( aim_speed, recoil - limit );
712}
double logarithmic_range(int min, int max, int pos)
Normalized logistic function.
double recoil
Definition: character.h:560
std::pair< int, int > get_fastest_sight(const item &gun, double recoil) const
Definition: character.cpp:577
double aim_speed_skill_modifier(const skill_id &gun_skill) const
Definition: character.cpp:618
double aim_speed_encumbrance_modifier() const
Definition: character.cpp:639
double aim_cap_from_volume(const item &gun) const
Definition: character.cpp:644
double aim_speed_dex_modifier() const
Definition: character.cpp:634
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6361
constexpr double MAX_RECOIL

References aim_cap_from_volume(), aim_speed_dex_modifier(), aim_speed_encumbrance_modifier(), aim_speed_skill_modifier(), get_fastest_sight(), item::gun_skill(), item::is_gun(), logarithmic_range(), MAX_RECOIL, and recoil.

Referenced by npc::aim(), do_aim(), player::gun_engagement_moves(), npc::method_of_attack(), and target_ui::panel_fire_mode_aim().

◆ aim_speed_dex_modifier()

double Character::aim_speed_dex_modifier ( ) const

Definition at line 634 of file character.cpp.

635{
636 return get_dex() - 8;
637}
virtual int get_dex() const
Definition: character.cpp:4084

References get_dex().

Referenced by aim_per_move().

◆ aim_speed_encumbrance_modifier()

double Character::aim_speed_encumbrance_modifier ( ) const

Definition at line 639 of file character.cpp.

640{
641 return ( encumb( bp_hand_l ) + encumb( bp_hand_r ) ) / 10.0;
642}
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4017

References bp_hand_l, bp_hand_r, and encumb().

Referenced by aim_per_move(), and get_encumbrance_description().

◆ aim_speed_skill_modifier()

double Character::aim_speed_skill_modifier ( const skill_id gun_skill) const
Pistol increases aiming speed for pistols Smg increases aiming speed for SMGs Rifle increases aiming speed for rifles Shotgun increases aiming speed for shotguns Launcher increases aiming speed for launchers

Definition at line 618 of file character.cpp.

619{
620 double skill_mult = 1.0;
621 if( gun_skill == skill_pistol ) {
622 skill_mult = 2.0;
623 } else if( gun_skill == skill_rifle ) {
624 skill_mult = 0.9;
625 }
626 /** @EFFECT_PISTOL increases aiming speed for pistols */
627 /** @EFFECT_SMG increases aiming speed for SMGs */
628 /** @EFFECT_RIFLE increases aiming speed for rifles */
629 /** @EFFECT_SHOTGUN increases aiming speed for shotguns */
630 /** @EFFECT_LAUNCHER increases aiming speed for launchers */
631 return skill_mult * std::min( MAX_SKILL, get_skill_level( gun_skill ) );
632}
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3359
static constexpr int MAX_SKILL

References get_skill_level(), MAX_SKILL, skill_pistol, and skill_rifle.

Referenced by aim_per_move().

◆ all_items_with_flag()

std::vector< const item * > Character::all_items_with_flag ( const std::string &  flag) const

All items that have the given flag (item::has_flag).

Definition at line 9605 of file character.cpp.

9606{
9607 return items_with( [&flag]( const item & it ) {
9608 return it.has_flag( flag );
9609 } );
9610}

References item::has_flag(), and visitable< Character >::items_with().

Referenced by iexamine::choose_fertilizer(), iexamine::dimensional_portal(), has_fire(), and use_fire().

◆ allergy_type()

morale_type Character::allergy_type ( const item food) const

Returns allergy type or MORALE_NULL if not allergic for this character.

Definition at line 615 of file consumption.cpp.

616{
617 using allergy_tuple = std::tuple<trait_id, std::string, morale_type>;
618 static const std::array<allergy_tuple, 8> allergy_tuples = {{
625 }
626 };
627
628 for( const auto &tp : allergy_tuples ) {
629 if( has_trait( std::get<0>( tp ) ) &&
630 food.has_flag( std::get<1>( tp ) ) ) {
631 return std::get<2>( tp );
632 }
633 }
634
635 return MORALE_NULL;
636}
static const std::string flag_ALLERGEN_MILK("ALLERGEN_MILK")
static const std::string flag_ALLERGEN_VEGGY("ALLERGEN_VEGGY")
static const std::string flag_ALLERGEN_JUNK("ALLERGEN_JUNK")
static const std::string flag_ALLERGEN_FRUIT("ALLERGEN_FRUIT")
static const trait_id trait_ANTIWHEAT("ANTIWHEAT")
static const trait_id trait_ANTIJUNK("ANTIJUNK")
static const trait_id trait_VEGETARIAN("VEGETARIAN")
static const trait_id trait_LACTOSE("LACTOSE")
static const std::string flag_ALLERGEN_WHEAT("ALLERGEN_WHEAT")
static const std::string flag_ALLERGEN_MEAT("ALLERGEN_MEAT")
static const trait_id trait_MEATARIAN("MEATARIAN")
static const trait_id trait_ANTIFRUIT("ANTIFRUIT")
const morale_type MORALE_MEATARIAN("morale_meatarian")
const morale_type MORALE_ANTIJUNK("morale_antijunk")
const morale_type MORALE_ANTIWHEAT("morale_antiwheat")
const morale_type MORALE_ANTIFRUIT("morale_antifruit")
const morale_type MORALE_LACTOSE("morale_lactose")
const morale_type MORALE_VEGETARIAN("morale_vegetarian")
const morale_type MORALE_NULL("morale_null")

References flag_ALLERGEN_FRUIT(), flag_ALLERGEN_JUNK(), flag_ALLERGEN_MEAT(), flag_ALLERGEN_MILK(), flag_ALLERGEN_VEGGY(), flag_ALLERGEN_WHEAT(), item::has_flag(), has_trait(), MORALE_ANTIFRUIT, MORALE_ANTIJUNK, MORALE_ANTIWHEAT, MORALE_LACTOSE, MORALE_MEATARIAN, MORALE_NULL, MORALE_VEGETARIAN, trait_ANTIFRUIT, trait_ANTIJUNK, trait_ANTIWHEAT, trait_LACTOSE, trait_MEATARIAN, and trait_VEGETARIAN.

Referenced by item::color_in_inventory(), modify_morale(), and will_eat().

◆ allocated_invlets()

invlets_bitset Character::allocated_invlets ( ) const

Only use for UI things.

Returns all invlets that are currently used in the player inventory, the weapon slot and the worn items.

Definition at line 2550 of file character.cpp.

2551{
2553
2554 invlets.set( weapon.invlet );
2555 for( const auto &w : worn ) {
2556 invlets.set( w.invlet );
2557 }
2558
2559 invlets[0] = false;
2560
2561 return invlets;
2562}
inventory inv
Definition: character.h:1527
invlets_bitset allocated_invlets() const
Definition: inventory.cpp:1258
std::bitset< std::numeric_limits< char >::max()> invlets_bitset
Definition: inventory.h:36

References inventory::allocated_invlets(), inv, item::invlet, weapon, and worn.

Referenced by inventory::assign_empty_invlet(), game_menus::inv::common(), and i_add().

◆ ammo_count_for()

int Character::ammo_count_for ( const item gun)

Counts ammo and UPS charges (lower of) for a given gun on the character.

Definition at line 6530 of file character.cpp.

6531{
6533 if( !gun.is_gun() ) {
6534 return ret;
6535 }
6536
6537 int required = gun.ammo_required();
6538
6539 if( required > 0 ) {
6540 int total_ammo = 0;
6541 total_ammo += gun.ammo_remaining();
6542
6543 bool has_mag = gun.magazine_integral();
6544
6545 const auto found_ammo = find_ammo( gun, true, -1 );
6546 int loose_ammo = 0;
6547 for( const auto &ammo : found_ammo ) {
6548 if( ammo->is_magazine() ) {
6549 has_mag = true;
6550 total_ammo += ammo->ammo_remaining();
6551 } else if( ammo->is_ammo() ) {
6552 loose_ammo += ammo->charges;
6553 }
6554 }
6555
6556 if( has_mag ) {
6557 total_ammo += loose_ammo;
6558 }
6559
6560 ret = std::min( ret, total_ammo / required );
6561 }
6562
6563 int ups_drain = gun.get_gun_ups_drain();
6564 if( ups_drain > 0 ) {
6565 ret = std::min( ret, charges_of( itype_UPS ) / ups_drain );
6566 }
6567
6568 return ret;
6569}
static const itype_id itype_UPS("UPS")
std::vector< item_location > find_ammo(const item &obj, bool empty=true, int radius=1) const
Searches for ammo or magazines that can be used to reload obj.
Definition: character.cpp:2679
static const int INFINITE_CHARGES
Definition: item.h:2154
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7220
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7290
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7497
int get_gun_ups_drain() const
Definition: item.cpp:9753
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:943

References item::ammo_remaining(), item::ammo_required(), visitable< Character >::charges_of(), find_ammo(), item::get_gun_ups_drain(), item::INFINITE_CHARGES, item::is_gun(), itype_UPS, item::magazine_integral(), and cata::hash64_detail::ret.

Referenced by give_item_to().

◆ amount_of_storage_bionics()

std::pair< int, int > Character::amount_of_storage_bionics ( ) const

Returns amount of Storage CBMs in the corpse.

Definition at line 2628 of file bionics.cpp.

2629{
2631
2632 // exclude amount of power capacity obtained via non-power-storage CBMs
2633 for( const bionic &it : *my_bionics ) {
2634 lvl -= it.info().capacity;
2635 }
2636
2637 std::pair<int, int> results( 0, 0 );
2638 if( lvl <= 0_kJ ) {
2639 return results;
2640 }
2641
2642 const units::energy pow_mkI = bio_power_storage->capacity;
2644
2645 while( lvl >= std::min( pow_mkI, pow_mkII ) ) {
2646 if( one_in( 2 ) ) {
2647 if( lvl >= pow_mkI ) {
2648 results.first++;
2649 lvl -= pow_mkI;
2650 }
2651 } else {
2652 if( lvl >= pow_mkII ) {
2653 results.second++;
2654 lvl -= pow_mkII;
2655 }
2656 }
2657 }
2658 return results;
2659}
units::energy get_max_power_level() const
Definition: character.cpp:1975
units::energy capacity
Power bank size.
Definition: bionics.h:45

References bio_power_storage, bio_power_storage_mkII, bionic_data::capacity, get_max_power_level(), my_bionics, and one_in().

Referenced by place_corpse().

◆ amount_worn()

int Character::amount_worn ( const itype_id id) const

Returns the amount of item ‘type’ that is currently worn.

Definition at line 2244 of file character.cpp.

2245{
2246 int amount = 0;
2247 for( auto &elem : worn ) {
2248 if( elem.typeId() == id ) {
2249 ++amount;
2250 }
2251 }
2252 return amount;
2253}

References worn.

Referenced by can_wear().

◆ apply_damage()

void Character::apply_damage ( Creature source,
bodypart_id  hurt,
int  dam,
bool  bypass_med = false 
)
overridevirtual

Actually hurt the player, hurts a body_part directly, no armor reduction.

Implements Creature.

Definition at line 8421 of file character.cpp.

8423{
8425 // don't do any more damage if we're already dead
8426 // Or if we're debugging and don't want to die
8427 return;
8428 }
8429
8430 if( hurt == bodypart_id( "num_bp" ) ) {
8431 debugmsg( "Wacky body part hurt!" );
8432 hurt = bodypart_id( "torso" );
8433 }
8434
8435 mod_pain( dam / 2 );
8436
8437 const bodypart_id &part_to_damage = hurt->main_part;
8438
8439 const int dam_to_bodypart = std::min( dam, get_part_hp_cur( part_to_damage ) );
8440
8441 mod_part_hp_cur( part_to_damage, - dam_to_bodypart );
8443
8444 if( !weapon.is_null() && !as_player()->can_wield( weapon ).success() &&
8445 can_unwield( weapon ).success() ) {
8446 add_msg_if_player( _( "You are no longer able to wield your %s and drop it!" ),
8447 weapon.display_name() );
8449 i_rem( &weapon );
8450 }
8451 if( has_effect( effect_mending, part_to_damage->token ) ) {
8452 effect &e = get_effect( effect_mending, part_to_damage->token );
8453 float remove_mend = dam / 20.0f;
8454 e.mod_duration( -e.get_max_duration() * remove_mend );
8455 }
8456
8457 if( dam > get_painkiller() ) {
8458 on_hurt( source );
8459 }
8460
8461 if( !bypass_med ) {
8462 // remove healing effects if damaged
8463 int remove_med = roll_remainder( dam / 5.0f );
8464 if( remove_med > 0 && has_effect( effect_bandaged, part_to_damage->token ) ) {
8465 remove_med -= reduce_healing_effect( effect_bandaged, remove_med, part_to_damage );
8466 }
8467 if( remove_med > 0 && has_effect( effect_disinfected, part_to_damage->token ) ) {
8468 reduce_healing_effect( effect_disinfected, remove_med, part_to_damage );
8469 }
8470 }
8471}
void put_into_vehicle_or_drop(Character &c, item_drop_reason, const std::list< item > &items)
static const trait_id trait_DEBUG_NODMG("DEBUG_NODMG")
static const efftype_id effect_bandaged("bandaged")
static const efftype_id effect_disinfected("disinfected")
static const efftype_id effect_mending("mending")
int get_painkiller() const
Returns intensity of painkillers
Definition: character.cpp:9818
item i_rem(int pos)
Remove a specific item from player possession.
Definition: character.cpp:2427
int reduce_healing_effect(const efftype_id &eff_id, int remove_med, const bodypart_id &hurt)
Reduce healing effect intensity, return initial intensity of the effect.
Definition: character.cpp:8629
void on_hurt(Creature *source, bool disturb=true)
Handles effects that happen when the player is damaged and aware of the fact.
Definition: character.cpp:8702
ret_val< bool > can_unwield(const item &it) const
Check player capable of unwielding an item.
Definition: character.cpp:3158
void mod_part_hp_cur(const bodypart_id &id, int mod)
Definition: creature.cpp:1590
virtual void mod_pain(int npain)
Definition: creature.cpp:1347
virtual bool is_dead_state() const =0
int get_part_hp_cur(const bodypart_id &id) const
Definition: creature.cpp:1560
Definition: effect.h:161
void mod_duration(const time_duration &dur, bool alert=false)
Mods the duration, capping at max_duration if it exists.
Definition: effect.cpp:821
time_duration get_max_duration() const
Returns the maximum duration of an effect.
Definition: effect.cpp:801
void send(const cata::event &) const
Definition: event_bus.cpp:58
std::string display_name(unsigned int quantity=1) const
Returns the item name and the charges or contained charges (if the item can have charges at all).
Definition: item.cpp:4700
ret_val< bool > can_wield(const item &it) const
Check player capable of wielding an item.
Definition: player.cpp:2386
@ character_takes_damage
event_bus & get_event_bus()
Definition: game.cpp:12619

References _, Creature::add_msg_if_player(), Creature::as_player(), can_unwield(), player::can_wield(), character_takes_damage, debugmsg, item::display_name(), effect_bandaged, effect_disinfected, effect_mending, Creature::get_effect(), get_event_bus(), effect::get_max_duration(), get_painkiller(), Creature::get_part_hp_cur(), getID(), Creature::has_effect(), has_trait(), i_rem(), Creature::is_dead_state(), item::is_null(), effect::mod_duration(), Creature::mod_pain(), Creature::mod_part_hp_cur(), on_hurt(), put_into_vehicle_or_drop(), reduce_healing_effect(), roll_remainder(), event_bus::send(), trait_DEBUG_NODMG, tumbling, and weapon.

Referenced by activate_bionic(), iuse::blech(), cough(), debug_menu::debug(), do_damage_for_bionic_failure(), eff_fun_bleed(), eff_fun_fungus(), iuse::ehandcuffs(), game::find_or_make_stairs(), heal_actor::finish_using(), iexamine::flower_cactus(), iexamine::flower_poppy(), start_location::handle_heli_crash(), player::hardcoded_effects(), player::knock_back_to(), activity_handlers::operation_do_turn(), player::process_one_effect(), suffer_from_radiation(), suffer_from_sunburn(), suffer_water_damage(), and suffer_while_underwater().

◆ apply_mods()

void Character::apply_mods ( const trait_id mut,
bool  add_remove 
)
protected

Applies stat mods to character.

Definition at line 206 of file mutation.cpp.

207{
208 int sign = add_remove ? 1 : -1;
209 int str_change = get_mod( mut, "STR" );
210 str_max += sign * str_change;
211 per_max += sign * get_mod( mut, "PER" );
212 dex_max += sign * get_mod( mut, "DEX" );
213 int_max += sign * get_mod( mut, "INT" );
214
215 if( str_change != 0 ) {
216 recalc_hp();
217 }
218}
void recalc_hp()
Recalculates HP after a change to max strength.
Definition: character.cpp:1659
int get_mod(const trait_id &mut, const std::string &arg) const
Retrieves a stat mod of a mutation.
Definition: mutation.cpp:195

References dex_max, get_mod(), int_max, per_max, recalc_hp(), and str_max.

Referenced by deactivate_mutation(), mutation_effect(), mutation_loss_effect(), mutation_spend_resources(), and suffer_mutation_power().

◆ apply_persistent_morale()

void Character::apply_persistent_morale ( )

Ensures persistent morale effects are up-to-date.

Definition at line 9020 of file character.cpp.

9021{
9022 // Hoarders get a morale penalty if they're not carrying a full inventory.
9023 if( has_trait( trait_HOARDER ) ) {
9024 int pen = ( volume_capacity() - volume_carried() ) / 125_ml;
9025 if( pen > 70 ) {
9026 pen = 70;
9027 }
9028 if( pen <= 0 ) {
9029 pen = 0;
9030 }
9031 if( has_effect( effect_took_xanax ) ) {
9032 pen = pen / 7;
9033 } else if( has_effect( effect_took_prozac ) ) {
9034 pen = pen / 2;
9035 }
9036 if( pen > 0 ) {
9037 add_morale( MORALE_PERM_HOARDER, -pen, -pen, 1_minutes, 1_minutes, true );
9038 }
9039 }
9040 // Nomads get a morale penalty if they stay near the same overmap tiles too long.
9042 const tripoint_abs_omt ompos = global_omt_location();
9043 float total_time = 0;
9044 // Check how long we've stayed in any overmap tile within 5 of us.
9045 const int max_dist = 5;
9046 for( const tripoint_abs_omt &pos : points_in_radius( ompos, max_dist ) ) {
9047 const float dist = rl_dist( ompos, pos );
9048 if( dist > max_dist ) {
9049 continue;
9050 }
9051 const auto iter = overmap_time.find( pos.xy() );
9052 if( iter == overmap_time.end() ) {
9053 continue;
9054 }
9055 // Count time in own tile fully, tiles one away as 4/5, tiles two away as 3/5, etc.
9056 total_time += to_moves<float>( iter->second ) * ( max_dist - dist ) / max_dist;
9057 }
9058 // Characters with higher tiers of Nomad suffer worse morale penalties, faster.
9059 int max_unhappiness;
9060 float min_time, max_time;
9061 if( has_trait( trait_NOMAD ) ) {
9062 max_unhappiness = 20;
9063 min_time = to_moves<float>( 2_days );
9064 max_time = to_moves<float>( 4_days );
9065 } else if( has_trait( trait_NOMAD2 ) ) {
9066 max_unhappiness = 40;
9067 min_time = to_moves<float>( 1_days );
9068 max_time = to_moves<float>( 2_days );
9069 } else { // traid_NOMAD3
9070 max_unhappiness = 60;
9071 min_time = to_moves<float>( 12_hours );
9072 max_time = to_moves<float>( 1_days );
9073 }
9074 // The penalty starts at 1 at min_time and scales up to max_unhappiness at max_time.
9075 const float t = ( total_time - min_time ) / ( max_time - min_time );
9076 const int pen = std::ceil( lerp_clamped( 0, max_unhappiness, t ) );
9077 if( pen > 0 ) {
9078 add_morale( MORALE_PERM_NOMAD, -pen, -pen, 1_minutes, 1_minutes, true );
9079 }
9080 }
9081
9082 if( has_trait( trait_PROF_FOODP ) ) {
9083 // Loosing your face is distressing
9084 if( !( is_wearing( itype_id( "foodperson_mask" ) ) ||
9085 is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
9086 add_morale( MORALE_PERM_NOFACE, -20, -20, 1_minutes, 1_minutes, true );
9087 } else if( is_wearing( itype_id( "foodperson_mask" ) ) ||
9088 is_wearing( itype_id( "foodperson_mask_on" ) ) ) {
9090 }
9091
9092 if( is_wearing( itype_id( "foodperson_mask_on" ) ) ) {
9093 add_morale( MORALE_PERM_FPMODE_ON, 10, 10, 1_minutes, 1_minutes, true );
9094 } else {
9096 }
9097 }
9098}
constexpr T lerp_clamped(const T &min, const T &max, float t)
Linear interpolation with t clamped to [0, 1].
Definition: cata_utility.h:162
static const efftype_id effect_took_prozac("took_prozac")
static const trait_id trait_PROF_FOODP("PROF_FOODP")
static const trait_id trait_HOARDER("HOARDER")
static const trait_id trait_NOMAD2("NOMAD2")
static const trait_id trait_NOMAD3("NOMAD3")
static const trait_id trait_NOMAD("NOMAD")
static const efftype_id effect_took_xanax("took_xanax")
units::volume volume_capacity() const
Definition: character.cpp:2854
std::unordered_map< point_abs_omt, time_duration > overmap_time
Amount of time the player has spent in each overmap tile.
Definition: character.h:2211
units::volume volume_carried() const
Definition: character.cpp:2727
void add_morale(const morale_type &type, int bonus, int max_bonus=0, const time_duration &duration=1_hours, const time_duration &decay_start=30_minutes, bool capped=false, const itype *item_type=nullptr)
Definition: character.cpp:9105
void rem_morale(const morale_type &type)
Definition: character.cpp:9126
bool is_wearing(const item &itm) const
Returns true if the player is wearing the item.
Definition: character.cpp:3243
tripoint_range< Tripoint > points_in_radius(const Tripoint &center, const int radius, const int radiusz=0)
Definition: map_iterator.h:125
const morale_type MORALE_PERM_FPMODE_ON("morale_perm_fpmode_on")
const morale_type MORALE_PERM_HOARDER("morale_perm_hoarder")
const morale_type MORALE_PERM_NOMAD("morale_perm_nomad")
const morale_type MORALE_PERM_NOFACE("morale_perm_noface")
constexpr point xy() const
Definition: point.h:220

References add_morale(), effect_took_prozac, effect_took_xanax, global_omt_location(), Creature::has_effect(), has_trait(), is_wearing(), itype_id, lerp_clamped(), MORALE_PERM_FPMODE_ON, MORALE_PERM_HOARDER, MORALE_PERM_NOFACE, MORALE_PERM_NOMAD, overmap_time, points_in_radius(), pos(), rem_morale(), rl_dist(), trait_HOARDER, trait_NOMAD, trait_NOMAD2, trait_NOMAD3, trait_PROF_FOODP, volume_capacity(), volume_carried(), and tripoint::xy().

Referenced by debug_menu::character_edit_menu(), check_and_recover_morale(), avatar::create(), and update_morale().

◆ apply_skill_boost()

void Character::apply_skill_boost ( )
private

Applies skill-based boosts to stats.

Definition at line 3504 of file character.cpp.

3505{
3506 for( const skill_boost &boost : skill_boost::get_all() ) {
3507 // For migration, reset previously applied bonus.
3508 // Remove after 0.E or so.
3509 const std::string bonus_name = boost.stat() + std::string( "_bonus" );
3510 std::string previous_bonus = get_value( bonus_name );
3511 if( !previous_bonus.empty() ) {
3512 if( boost.stat() == "str" ) {
3513 str_max -= atoi( previous_bonus.c_str() );
3514 } else if( boost.stat() == "dex" ) {
3515 dex_max -= atoi( previous_bonus.c_str() );
3516 } else if( boost.stat() == "int" ) {
3517 int_max -= atoi( previous_bonus.c_str() );
3518 } else if( boost.stat() == "per" ) {
3519 per_max -= atoi( previous_bonus.c_str() );
3520 }
3521 remove_value( bonus_name );
3522 }
3523 // End migration code
3524 int skill_total = 0;
3525 for( const std::string &skill_str : boost.skills() ) {
3526 skill_total += get_skill_level( skill_id( skill_str ) );
3527 }
3528 mod_stat( boost.stat(), boost.calc_bonus( skill_total ) );
3529 if( boost.stat() == "str" ) {
3530 recalc_hp();
3531 }
3532 }
3533}
void mod_stat(const std::string &stat, float modifier) override
Definition: character.cpp:520
void remove_value(const std::string &key)
Definition: creature.cpp:1336
static const std::vector< skill_boost > & get_all()
Definition: skill_boost.cpp:15

References dex_max, skill_boost::get_all(), get_skill_level(), Creature::get_value(), int_max, mod_stat(), per_max, recalc_hp(), Creature::remove_value(), skill_id, and str_max.

Referenced by reset_stats().

◆ apply_wetness_morale()

void Character::apply_wetness_morale ( int  temperature)

Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature.

Definition at line 1805 of file suffer.cpp.

1806{
1807 // First, a quick check if we have any wetness to calculate morale from
1808 // Faster than checking all worn items for friendliness
1809 if( !std::any_of( body_wetness.begin(), body_wetness.end(),
1810 []( const int w ) {
1811 return w != 0;
1812} ) ) {
1813 return;
1814 }
1815
1816 // Normalize temperature to [-1.0,1.0]
1817 temperature = std::max( 0, std::min( 100, temperature ) );
1818 const double global_temperature_mod = -1.0 + ( 2.0 * temperature / 100.0 );
1819
1820 int total_morale = 0;
1821 const auto wet_friendliness = exclusive_flag_coverage( "WATER_FRIENDLY" );
1822 for( const body_part bp : all_body_parts ) {
1823 // Sum of body wetness can go up to 103
1824 const int part_drench = body_wetness[bp];
1825 if( part_drench == 0 ) {
1826 continue;
1827 }
1828
1829 const auto &part_arr = mut_drench[bp];
1830 const int part_ignored = part_arr[WT_IGNORED];
1831 const int part_neutral = part_arr[WT_NEUTRAL];
1832 const int part_good = part_arr[WT_GOOD];
1833
1834 if( part_ignored >= part_drench ) {
1835 continue;
1836 }
1837
1838 int bp_morale = 0;
1839 const bool is_friendly = wet_friendliness.test( bp );
1840 const int effective_drench = part_drench - part_ignored;
1841 if( is_friendly ) {
1842 // Using entire bonus from mutations and then some "human" bonus
1843 bp_morale = std::min( part_good, effective_drench ) + effective_drench / 2;
1844 } else if( effective_drench < part_good ) {
1845 // Positive or 0
1846 // Won't go higher than part_good / 2
1847 // Wet slime/scale doesn't feel as good when covered by wet rags/fur/kevlar
1848 bp_morale = std::min( effective_drench, part_good - effective_drench );
1849 } else if( effective_drench > part_good + part_neutral ) {
1850 // This one will be negative
1851 bp_morale = part_good + part_neutral - effective_drench;
1852 }
1853
1854 // Clamp to [COLD,HOT] and cast to double
1855 const double part_temperature =
1856 std::min( BODYTEMP_HOT, std::max( BODYTEMP_COLD, temp_cur[bp] ) );
1857 // 0.0 at COLD, 1.0 at HOT
1858 const double part_mod = ( part_temperature - BODYTEMP_COLD ) /
1860 // Average of global and part temperature modifiers, each in range [-1.0, 1.0]
1861 double scaled_temperature = ( global_temperature_mod + part_mod ) / 2;
1862
1863 if( bp_morale < 0 ) {
1864 // Damp, hot clothing on hot skin feels bad
1865 scaled_temperature = std::fabs( scaled_temperature );
1866 }
1867
1868 // For an unmutated human swimming in deep water, this will add up to:
1869 // +51 when hot in 100% water friendly clothing
1870 // -103 when cold/hot in 100% unfriendly clothing
1871 total_morale += static_cast<int>( bp_morale * ( 1.0 + scaled_temperature ) / 2.0 );
1872 }
1873
1874 if( total_morale == 0 ) {
1875 return;
1876 }
1877
1878 int morale_effect = total_morale / 8;
1879 if( morale_effect == 0 ) {
1880 if( total_morale > 0 ) {
1881 morale_effect = 1;
1882 } else {
1883 morale_effect = -1;
1884 }
1885 }
1886 // 61_seconds because decay is applied in 1_minutes increments
1887 add_morale( MORALE_WET, morale_effect, total_morale, 61_seconds, 61_seconds, true );
1888}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:82
body_part
Definition: bodypart.h:39
body_part_set exclusive_flag_coverage(const std::string &flag) const
Bitset of all the body parts covered only with items with flag (or nothing)
Definition: character.cpp:4060
std::array< std::array< int, NUM_WATER_TOLERANCE >, num_bp > mut_drench
Definition: character.h:844
const morale_type MORALE_WET("morale_wet")
quantity< V, U > fabs(quantity< V, U > q)
Definition: units_def.h:136
quantity< int, temperature_in_millidegree_celsius_tag > temperature
static constexpr int BODYTEMP_COLD
Do not change this value, it is an arbitrary anchor on which other calculations are made.
Definition: weather.h:34
static constexpr int BODYTEMP_HOT
Level 2 hotness.
Definition: weather.h:38

References add_morale(), all_body_parts, body_wetness, BODYTEMP_COLD, BODYTEMP_HOT, exclusive_flag_coverage(), units::fabs(), MORALE_WET, mut_drench, temp_cur, WT_GOOD, WT_IGNORED, and WT_NEUTRAL.

Referenced by game::do_turn().

◆ armor_absorb()

bool Character::armor_absorb ( damage_unit du,
item armor 
)

Reduces and mutates du, prints messages about armor taking damage.

Returns
true if the armor was completely destroyed (and the item must be deleted).

Definition at line 8308 of file character.cpp.

8309{
8310 if( rng( 1, 100 ) > armor.get_coverage() ) {
8311 return false;
8312 }
8313
8314 // TODO: add some check for power armor
8315 armor.mitigate_damage( du );
8316
8317 // We want armor's own resistance to this type, not the resistance it grants
8318 const int armors_own_resist = armor.damage_resist( du.type, true );
8319 if( armors_own_resist > 1000 ) {
8320 // This is some weird type that doesn't damage armors
8321 return false;
8322 }
8323
8324 // Scale chance of article taking damage based on the number of parts it covers.
8325 // This represents large articles being able to take more punishment
8326 // before becoming ineffective or being destroyed.
8327 const int num_parts_covered = armor.get_covered_body_parts().count();
8328 if( !one_in( num_parts_covered ) ) {
8329 return false;
8330 }
8331
8332 // Don't damage armor as much when bypassed by armor piercing
8333 // Most armor piercing damage comes from bypassing armor, not forcing through
8334 const int raw_dmg = du.amount;
8335 if( raw_dmg > armors_own_resist ) {
8336 // If damage is above armor value, the chance to avoid armor damage is
8337 // 50% + 50% * 1/dmg
8338 if( one_in( raw_dmg ) || one_in( 2 ) ) {
8339 return false;
8340 }
8341 } else {
8342 // Sturdy items and power armors never take chip damage.
8343 // Other armors have 0.5% of getting damaged from hits below their armor value.
8344 if( armor.has_flag( flag_STURDY ) || !one_in( 200 ) ) {
8345 return false;
8346 }
8347 }
8348
8349 const material_type &material = armor.get_random_material();
8350 std::string damage_verb = ( du.type == DT_BASH ) ? material.bash_dmg_verb() :
8351 material.cut_dmg_verb();
8352
8353 const std::string pre_damage_name = armor.tname();
8354 const std::string pre_damage_adj = armor.get_base_material().dmg_adj( armor.damage_level( 4 ) );
8355
8356 // add "further" if the damage adjective and verb are the same
8357 std::string format_string = ( pre_damage_adj == damage_verb ) ?
8358 _( "Your %1$s is %2$s further!" ) : _( "Your %1$s is %2$s!" );
8359 add_msg_if_player( m_bad, format_string, pre_damage_name, damage_verb );
8360 //item is damaged
8361 if( is_player() ) {
8362 SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ), m_neutral,
8363 damage_verb,
8364 m_info );
8365 }
8366
8367 return armor.mod_damage( armor.has_flag( "FRAGILE" ) ?
8369}
static const std::string flag_STURDY("STURDY")
virtual bool is_player() const
Definition: creature.h:92
size_t count() const
Definition: bodypart.h:252
const material_type & get_random_material() const
Get a material reference to a random material that this item is made of.
Definition: item.cpp:6979
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6070
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:700
int damage_resist(damage_type dt, bool to_self=false) const
Resistance provided by this item against damage type given by an enum.
Definition: item.cpp:6215
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:6984
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:752
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5744
void mitigate_damage(damage_unit &du) const
Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type...
Definition: item.cpp:6207
std::string cut_dmg_verb() const
Definition: material.cpp:190
std::string dmg_adj(int damage) const
Definition: material.cpp:195
std::string bash_dmg_verb() const
Definition: material.cpp:185
static constexpr int damage_scale
Definition: itype.h:1008

References _, scrollingcombattext::add(), Creature::add_msg_if_player(), damage_unit::amount, material_type::bash_dmg_verb(), body_part_set::count(), material_type::cut_dmg_verb(), item::damage_level(), item::damage_resist(), itype::damage_scale, material_type::dmg_adj(), DT_BASH, flag_STURDY(), item::get_base_material(), item::get_coverage(), item::get_covered_body_parts(), item::get_random_material(), item::has_flag(), Creature::is_player(), m_bad, m_info, m_neutral, item::mitigate_damage(), item::mod_damage(), NORTH, one_in(), posx(), posy(), remove_color_tags(), rng(), SCT, item::tname(), and damage_unit::type.

Referenced by absorb_hit().

◆ armwear_factor()

double Character::armwear_factor ( ) const

Same as footwear factor, but for arms.

Definition at line 8937 of file character.cpp.

8938{
8939 double ret = 0;
8940 if( wearing_something_on( bodypart_id( "arm_l" ) ) ) {
8941 ret += .5;
8942 }
8943 if( wearing_something_on( bodypart_id( "arm_r" ) ) ) {
8944 ret += .5;
8945 }
8946 return ret;
8947}
bool wearing_something_on(const bodypart_id &bp) const
Returns true if the character is wearing something on the entered body part.
Definition: character.cpp:8873

References cata::hash64_detail::ret, and wearing_something_on().

Referenced by suffer_in_sunlight().

◆ as_character() [1/2]

const Character * Character::as_character ( ) const
inlineoverridevirtual

Reimplemented from Creature.

Definition at line 211 of file character.h.

211 {
212 return this;
213 }

◆ as_character() [2/2]

Character * Character::as_character ( )
inlineoverridevirtual

Reimplemented from Creature.

Definition at line 208 of file character.h.

208 {
209 return this;
210 }

Referenced by doors::close_door(), and emit_radio_signal().

◆ assign_activity() [1/2]

void Character::assign_activity ( const activity_id type,
int  moves = calendar::INDEFINITELY_LONG,
int  index = -1,
int  pos = INT_MIN,
const std::string &  name = "" 
)

Legacy activity assignment, does not work for any activites using the new activity_actor class and may cause issues with resuming.

TODO: delete this once migration of activites to the activity_actor system is complete

Definition at line 9203 of file character.cpp.

9205{
9207}
int moves
Definition: creature.h:569

References assign_activity(), Creature::moves, name, pos(), and type.

Referenced by activate_mutation(), activity_on_turn_move_loot(), assign_activity(), iuse::burrow(), game::butcher(), butcher_corpse_activity(), cast_spell(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), complete_construction(), construction_activity(), iuse::craft(), iuse::cut_log_into_planks(), iuse::dig(), iuse::dig_channel(), player::disassemble(), player::disassemble_all(), overmap_ui::display(), talk_function::do_butcher(), talk_function::do_chop_plank(), talk_function::do_chop_trees(), talk_function::do_construction(), talk_function::do_farming(), talk_function::do_fishing(), talk_function::do_mining(), npc::do_pulp(), player_activity::do_turn(), talk_function::do_vehicle_deconstruct(), talk_function::do_vehicle_repair(), drop(), game::exam_vehicle(), iuse::fill_pit(), npc::find_job_to_perform(), talk_function::find_mount(), avatar_action::fire_ranged_bionic(), avatar_action::fire_ranged_mutation(), avatar_action::fire_wielded_weapon(), activity_handlers::fish_finish(), iuse::fishing_rod(), generic_multi_activity_check_requirement(), generic_multi_activity_do(), generic_multi_activity_handler(), talk_function::give_aid(), talk_function::give_all_aid(), player::gunmod_add(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::hand_crank(), install_bionics(), iuse::jackhammer(), loot(), iuse::makemound(), iuse::meditate(), iuse::mind_splicer(), mine_activity(), gates::open_gate(), iuse::oxytorch(), iuse::pickaxe(), game::place_player(), iexamine::plant_seed(), iuse::play_game(), iuse::portable_game(), avatar::read(), game::reload(), activity_handlers::resume_for_multi_activities(), iuse::robotcontrol(), iexamine::rubble(), iexamine::safe(), iuse::shavekit(), iexamine::shrub_wildveggies(), smash(), talk_function::sort_loot(), player::start_craft(), start_destination_activity(), game::start_hauling(), npc::start_read(), player::toolmod_add(), try_start_hacking(), player::try_to_sleep(), uninstall_bionic(), pick_lock_actor::use(), firestarter_actor::use(), enzlave_actor::use(), ammobelt_actor::use(), repair_item_actor::use(), heal_actor::use(), learn_spell_actor::use(), cast_spell_actor::use(), vehicle_activity(), iuse::vibe(), wait(), and wash_items().

◆ assign_activity() [2/2]

void Character::assign_activity ( const player_activity act,
bool  allow_resume = true 
)

Assigns activity to player, possibly resuming old activity if it's similar enough.

Definition at line 9209 of file character.cpp.

9210{
9211 bool resuming = false;
9212 if( allow_resume && !backlog.empty() && backlog.front().can_resume_with( act, *this ) ) {
9213 resuming = true;
9214 add_msg_if_player( _( "You resume your task." ) );
9215 activity = backlog.front();
9216 backlog.pop_front();
9217 } else {
9218 if( activity ) {
9219 backlog.push_front( activity );
9220 }
9221
9222 activity = act;
9223 }
9224
9225 activity.start_or_resume( *this, resuming );
9226
9227 if( is_npc() ) {
9229 npc *guy = dynamic_cast<npc *>( this );
9233 }
9234}
void cancel_stashed_activity()
Definition: character.cpp:967
std::list< player_activity > backlog
Definition: character.h:1525
virtual bool is_npc() const
Definition: creature.h:98
Definition: npc.h:781
void set_attitude(npc_attitude new_attitude)
Definition: npc.cpp:3141
activity_id current_activity_id
Definition: npc.h:1249
void set_mission(npc_mission new_mission)
Definition: npc.cpp:3120
const activity_id & id() const
void start_or_resume(Character &who, bool resuming)
Preform necessary initialization to start or resume the activity.
@ NPCATT_ACTIVITY
Definition: npc.h:98
@ NPC_MISSION_ACTIVITY
Definition: npc.h:190
activity_id act
Definition: sounds.cpp:75

References _, act, activity, Creature::add_msg_if_player(), backlog, cancel_stashed_activity(), npc::current_activity_id, player_activity::id(), Creature::is_npc(), NPC_MISSION_ACTIVITY, NPCATT_ACTIVITY, npc::set_attitude(), npc::set_mission(), and player_activity::start_or_resume().

◆ assign_stashed_activity()

void Character::assign_stashed_activity ( )

Definition at line 989 of file character.cpp.

990{
994}
player_activity stashed_outbounds_backlog
Definition: character.h:1523
player_activity stashed_outbounds_activity
Definition: character.h:1522

References activity, backlog, cancel_stashed_activity(), stashed_outbounds_activity, and stashed_outbounds_backlog.

Referenced by npc::move().

◆ attack_cost()

int Character::attack_cost ( const item weap) const

Returns cost (in moves) of attacking with given item (no modifiers, like stuck)

Melee increases melee attack speed Dexterity increases attack speed

Definition at line 2194 of file melee.cpp.

2195{
2196 const int base_move_cost = weap.attack_cost() / 2;
2197 const int melee_skill = has_active_bionic( bionic_id( bio_cqb ) ) ? BIO_CQB_LEVEL : get_skill_level(
2198 skill_melee );
2199 /** @EFFECT_MELEE increases melee attack speed */
2200 const int skill_cost = static_cast<int>( ( base_move_cost * ( 15 - melee_skill ) / 15 ) );
2201 /** @EFFECT_DEX increases attack speed */
2202 const int dexbonus = dex_cur / 2;
2203 const int encumbrance_penalty = encumb( bp_torso ) +
2204 ( encumb( bp_hand_l ) + encumb( bp_hand_r ) ) / 2;
2205 const int ma_move_cost = mabuff_attack_cost_penalty();
2206 const float stamina_ratio = static_cast<float>( get_stamina() ) / static_cast<float>
2207 ( get_stamina_max() );
2208 // Increase cost multiplier linearly from 1.0 to 2.0 as stamina goes from 25% to 0%.
2209 const float stamina_penalty = 1.0 + std::max( ( 0.25f - stamina_ratio ) * 4.0f, 0.0f );
2210 const float ma_mult = mabuff_attack_cost_mult();
2211
2212 int move_cost = base_move_cost;
2213 // Stamina penalty only affects base/2 and encumbrance parts of the cost
2214 move_cost += encumbrance_penalty;
2215 move_cost *= stamina_penalty;
2216 move_cost += skill_cost;
2217 move_cost -= dexbonus;
2218
2220
2221 // Martial arts last. Flat has to be after mult, because comments say so.
2222 move_cost *= ma_mult;
2223 move_cost += ma_move_cost;
2224
2225 move_cost *= mutation_value( "attackcost_modifier" );
2226
2227 if( move_cost < 25 ) {
2228 return 25;
2229 }
2230
2231 return move_cost;
2232}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int get_stamina() const
Definition: character.cpp:7208
float mabuff_attack_cost_mult() const
Returns the multiplier on move cost of attacks.
float mutation_value(const std::string &val) const
Goes over all mutations, gets min and max of a value with given name.
Definition: character.cpp:6765
int mabuff_attack_cost_penalty() const
Returns the flat penalty to move cost of attacks.
double bonus_from_enchantments(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments for given base value.
Definition: character.cpp:8052
int get_stamina_max() const
Definition: character.cpp:7213
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5078
static constexpr int BIO_CQB_LEVEL
static const bionic_id bio_cqb("bio_cqb")
static const skill_id skill_melee("melee")

References item::attack_cost(), enchant_vals::ATTACK_COST, bio_cqb, BIO_CQB_LEVEL, bionic_id, bonus_from_enchantments(), bp_hand_l, bp_hand_r, bp_torso, dex_cur, encumb(), get_skill_level(), get_stamina(), get_stamina_max(), has_active_bionic(), mabuff_attack_cost_mult(), mabuff_attack_cost_penalty(), move_cost(), mutation_value(), and skill_melee.

Referenced by player::disarm(), item::effective_dps(), melee_attack(), and player::reach_attack().

◆ attitude_to()

Creature::Attitude Character::attitude_to ( const Creature other) const
overridevirtual

Attitude (of this creature) towards another creature.

This might not be symmetric.

Implements Creature.

Reimplemented in npc.

Definition at line 10380 of file character.cpp.

10381{
10382 const auto m = dynamic_cast<const monster *>( &other );
10383 if( m != nullptr ) {
10384 if( m->friendly != 0 ) {
10385 return A_FRIENDLY;
10386 }
10387 switch( m->attitude( const_cast<Character *>( this ) ) ) {
10388 // player probably does not want to harm them, but doesn't care much at all.
10389 case MATT_FOLLOW:
10390 case MATT_FPASSIVE:
10391 case MATT_IGNORE:
10392 case MATT_FLEE:
10393 return A_NEUTRAL;
10394 // player does not want to harm those.
10395 case MATT_FRIEND:
10396 case MATT_ZLAVE:
10397 // Don't want to harm your zlave!
10398 return A_FRIENDLY;
10399 case MATT_ATTACK:
10400 return A_HOSTILE;
10401 case MATT_NULL:
10403 break;
10404 }
10405
10406 return A_NEUTRAL;
10407 }
10408
10409 const auto p = dynamic_cast<const npc *>( &other );
10410 if( p != nullptr ) {
10411 if( p->is_enemy() ) {
10412 return A_HOSTILE;
10413 } else if( p->is_player_ally() ) {
10414 return A_FRIENDLY;
10415 } else {
10416 return A_NEUTRAL;
10417 }
10418 } else if( &other == this ) {
10419 return A_FRIENDLY;
10420 }
10421
10422 return A_NEUTRAL;
10423}
@ A_NEUTRAL
Definition: creature.h:170
@ A_HOSTILE
Definition: creature.h:169
@ A_FRIENDLY
Definition: creature.h:171
@ MATT_ZLAVE
Definition: monster.h:62
@ MATT_FLEE
Definition: monster.h:58
@ NUM_MONSTER_ATTITUDES
Definition: monster.h:63
@ MATT_FRIEND
Definition: monster.h:56
@ MATT_FOLLOW
Definition: monster.h:60
@ MATT_ATTACK
Definition: monster.h:61
@ MATT_NULL
Definition: monster.h:55
@ MATT_IGNORE
Definition: monster.h:59
@ MATT_FPASSIVE
Definition: monster.h:57

References Creature::A_FRIENDLY, Creature::A_HOSTILE, Creature::A_NEUTRAL, MATT_ATTACK, MATT_FLEE, MATT_FOLLOW, MATT_FPASSIVE, MATT_FRIEND, MATT_IGNORE, MATT_NULL, MATT_ZLAVE, NUM_MONSTER_ATTITUDES, and other.

Referenced by game::is_hostile_within(), and player::sort_armor().

◆ base_age()

int Character::base_age ( ) const

Definition at line 6900 of file character.cpp.

6901{
6902 return init_age;
6903}

References init_age.

Referenced by debug_menu::character_edit_menu(), char_creation::draw_age(), and set_description().

◆ base_comfort_value()

Character::comfort_response_t Character::base_comfort_value ( const tripoint p) const

Rate point's ability to serve as a bed.

Only takes certain mutations into account, and not fatigue nor stimulants.

Definition at line 5702 of file character.cpp.

5703{
5704 // Comfort of sleeping spots is "objective", while sleep_spot( p ) is "subjective"
5705 // As in the latter also checks for fatigue and other variables while this function
5706 // only looks at the base comfyness of something. It's still subjective, in a sense,
5707 // as arachnids who sleep in webs will find most places comfortable for instance.
5708 int comfort = 0;
5709
5710 comfort_response_t comfort_response;
5711
5712 bool plantsleep = has_trait( trait_CHLOROMORPH );
5713 bool fungaloid_cosplay = has_trait( trait_M_SKIN3 );
5714 bool websleep = has_trait( trait_WEB_WALKER );
5715 bool webforce = has_trait( trait_THRESH_SPIDER ) && ( has_trait( trait_WEB_SPINNER ) ||
5716 ( has_trait( trait_WEB_WEAVER ) ) );
5717 bool in_shell = has_active_mutation( trait_SHELL2 );
5718 bool watersleep = has_trait( trait_WATERSLEEP );
5719
5720 map &here = get_map();
5721 const optional_vpart_position vp = here.veh_at( p );
5722 const maptile tile = here.maptile_at( p );
5723 const trap &trap_at_pos = tile.get_trap_t();
5724 const ter_id ter_at_pos = tile.get_ter();
5725 const furn_id furn_at_pos = tile.get_furn();
5726
5727 int web = here.get_field_intensity( p, fd_web );
5728
5729 // Some mutants have different comfort needs
5730 if( !plantsleep && !webforce ) {
5731 if( in_shell ) {
5732 comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
5733 // Note: shelled individuals can still use sleeping aids!
5734 } else if( vp ) {
5735 const cata::optional<vpart_reference> carg = vp.part_with_feature( "CARGO", false );
5736 const cata::optional<vpart_reference> board = vp.part_with_feature( "BOARDABLE", true );
5737 if( carg ) {
5738 const vehicle_stack items = vp->vehicle().get_items( carg->part_index() );
5739 for( const item &items_it : items ) {
5740 if( items_it.has_flag( "SLEEP_AID" ) ) {
5741 // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable
5742 comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
5743 comfort_response.aid = &items_it;
5744 break; // prevents using more than 1 sleep aid
5745 }
5746 }
5747 }
5748 if( board ) {
5749 comfort += board->info().comfort;
5750 } else {
5751 comfort -= here.move_cost( p );
5752 }
5753 }
5754 // Not in a vehicle, start checking furniture/terrain/traps at this point in decreasing order
5755 else if( furn_at_pos != f_null ) {
5756 comfort += 0 + furn_at_pos.obj().comfort;
5757 }
5758 // Web sleepers can use their webs if better furniture isn't available
5759 else if( websleep && web >= 3 ) {
5760 comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
5761 } else if( ter_at_pos == t_improvised_shelter ) {
5762 comfort += 0 + static_cast<int>( comfort_level::slightly_comfortable );
5763 } else if( ter_at_pos == t_floor || ter_at_pos == t_floor_waxed ||
5764 ter_at_pos == t_carpet_red || ter_at_pos == t_carpet_yellow ||
5765 ter_at_pos == t_carpet_green || ter_at_pos == t_carpet_purple ) {
5766 comfort += 1 + static_cast<int>( comfort_level::neutral );
5767 } else if( !trap_at_pos.is_null() ) {
5768 comfort += 0 + trap_at_pos.comfort;
5769 } else {
5770 // Not a comfortable sleeping spot
5771 comfort -= here.move_cost( p );
5772 }
5773
5774 if( comfort_response.aid == nullptr ) {
5775 const map_stack items = here.i_at( p );
5776 for( const item &items_it : items ) {
5777 if( items_it.has_flag( "SLEEP_AID" ) ) {
5778 // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable
5779 comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
5780 comfort_response.aid = &items_it;
5781 break; // prevents using more than 1 sleep aid
5782 }
5783 }
5784 }
5785 if( fungaloid_cosplay && here.has_flag_ter_or_furn( flag_FUNGUS, pos() ) ) {
5786 comfort += static_cast<int>( comfort_level::very_comfortable );
5787 } else if( watersleep && here.has_flag_ter( flag_SWIMMABLE, pos() ) ) {
5788 comfort += static_cast<int>( comfort_level::very_comfortable );
5789 }
5790 } else if( plantsleep ) {
5791 if( vp || furn_at_pos != f_null ) {
5792 // Sleep ain't happening in a vehicle or on furniture
5793 comfort = static_cast<int>( comfort_level::impossible );
5794 } else {
5795 // It's very easy for Chloromorphs to get to sleep on soil!
5796 if( ter_at_pos == t_dirt || ter_at_pos == t_pit || ter_at_pos == t_dirtmound ||
5797 ter_at_pos == t_pit_shallow ) {
5798 comfort += static_cast<int>( comfort_level::very_comfortable );
5799 }
5800 // Not as much if you have to dig through stuff first
5801 else if( ter_at_pos == t_grass ) {
5802 comfort += static_cast<int>( comfort_level::comfortable );
5803 }
5804 // Sleep ain't happening
5805 else {
5806 comfort = static_cast<int>( comfort_level::impossible );
5807 }
5808 }
5809 // Has webforce
5810 } else {
5811 if( web >= 3 ) {
5812 // Thick Web and you're good to go
5813 comfort += static_cast<int>( comfort_level::very_comfortable );
5814 } else {
5815 comfort = static_cast<int>( comfort_level::impossible );
5816 }
5817 }
5818
5819 if( comfort > static_cast<int>( comfort_level::comfortable ) ) {
5820 comfort_response.level = comfort_level::very_comfortable;
5821 } else if( comfort > static_cast<int>( comfort_level::slightly_comfortable ) ) {
5822 comfort_response.level = comfort_level::comfortable;
5823 } else if( comfort > static_cast<int>( comfort_level::neutral ) ) {
5824 comfort_response.level = comfort_level::slightly_comfortable;
5825 } else if( comfort == static_cast<int>( comfort_level::neutral ) ) {
5826 comfort_response.level = comfort_level::neutral;
5827 } else {
5828 comfort_response.level = comfort_level::uncomfortable;
5829 }
5830 return comfort_response;
5831}
static const trait_id trait_M_SKIN3("M_SKIN3")
static const trait_id trait_WEB_WALKER("WEB_WALKER")
static const trait_id trait_WEB_WEAVER("WEB_WEAVER")
static const trait_id trait_WEB_SPINNER("WEB_SPINNER")
static const trait_id trait_SHELL2("SHELL2")
static const trait_id trait_CHLOROMORPH("CHLOROMORPH")
static const std::string flag_SWIMMABLE("SWIMMABLE")
static const trait_id trait_WATERSLEEP("WATERSLEEP")
static const std::string flag_FUNGUS("FUNGUS")
static const trait_id trait_THRESH_SPIDER("THRESH_SPIDER")
bool has_active_mutation(const trait_id &b) const
Definition: mutation.cpp:367
const T & obj() const
Definition: ammo_effect.cpp:26
maptile maptile_at(const tripoint &p) const
Definition: map.cpp:197
int get_field_intensity(const tripoint &p, const field_type_id &type) const
Get the intensity of a field entry (field_entry::intensity), if there is no field of that type,...
Definition: map.cpp:5357
bool has_flag_ter_or_furn(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2317
int move_cost(const tripoint &p, const vehicle *ignored_vehicle=nullptr) const
Calculate the cost to move past the tile at p.
Definition: map.cpp:1775
bool has_flag_ter(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2307
cata::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2481
ter_id t_floor_waxed
Definition: mapdata.cpp:632
ter_id t_improvised_shelter
Definition: mapdata.cpp:716
ter_id t_grass
Definition: mapdata.cpp:628
ter_id t_carpet_purple
Definition: mapdata.cpp:634
ter_id t_carpet_yellow
Definition: mapdata.cpp:634
ter_id t_dirt
Definition: mapdata.cpp:625
ter_id t_floor
Definition: mapdata.cpp:632
ter_id t_carpet_green
Definition: mapdata.cpp:634
ter_id t_pit_shallow
Definition: mapdata.cpp:625
ter_id t_carpet_red
Definition: mapdata.cpp:634
ter_id t_pit
Definition: mapdata.cpp:625
ter_id t_dirtmound
Definition: mapdata.cpp:625
bool board(const tripoint &p, Creature *c, item *i)
Definition: trapfunc.cpp:172
int comfort
Definition: mapdata.h:497
A wrapper for a submap point.
Definition: submap.h:267
furn_id get_furn() const
Definition: submap.h:285
ter_id get_ter() const
Definition: submap.h:289
const trap & get_trap_t() const
Definition: submap.h:293
int comfort
Definition: trap.h:119

References Character::comfort_response_t::aid, trapfunc::board(), furn_t::comfort, trap::comfort, comfortable, f_null, fd_web, flag_FUNGUS(), flag_SWIMMABLE(), map::get_field_intensity(), maptile::get_furn(), get_map(), maptile::get_ter(), maptile::get_trap_t(), has_active_mutation(), map::has_flag_ter(), map::has_flag_ter_or_furn(), has_trait(), map::i_at(), impossible, trap::is_null(), Character::comfort_response_t::level, map::maptile_at(), map::move_cost(), neutral, int_id< T >::obj(), optional_vpart_position::part_with_feature(), pos(), slightly_comfortable, t_carpet_green, t_carpet_purple, t_carpet_red, t_carpet_yellow, t_dirt, t_dirtmound, t_floor, t_floor_waxed, t_grass, t_improvised_shelter, t_pit, t_pit_shallow, trait_CHLOROMORPH, trait_M_SKIN3, trait_SHELL2, trait_THRESH_SPIDER, trait_WATERSLEEP, trait_WEB_SPINNER, trait_WEB_WALKER, trait_WEB_WEAVER, uncomfortable, map::veh_at(), and very_comfortable.

Referenced by player::sleep_spot(), and update_needs().

◆ base_height()

int Character::base_height ( ) const

Definition at line 6929 of file character.cpp.

6930{
6931 return init_height;
6932}
int init_height
height at character creation
Definition: character.h:2073

References init_height.

Referenced by debug_menu::character_edit_menu(), char_creation::draw_height(), and set_description().

◆ best_nearby_lifting_assist() [1/2]

int Character::best_nearby_lifting_assist ( ) const

Checks for items, tools, and vehicles with the Lifting quality near the character returning the highest quality in range.

Definition at line 2732 of file character.cpp.

2733{
2734 return best_nearby_lifting_assist( this->pos() );
2735}
int best_nearby_lifting_assist() const
Checks for items, tools, and vehicles with the Lifting quality near the character returning the highe...
Definition: character.cpp:2732

References best_nearby_lifting_assist(), and pos().

Referenced by best_nearby_lifting_assist(), can_do_activity_there(), and weight_carried_reduced_by().

◆ best_nearby_lifting_assist() [2/2]

int Character::best_nearby_lifting_assist ( const tripoint world_pos) const

Alternate version if you need to specify a different orign point for nearby vehicle sources of lifting used for operations on distant objects (e.g.

vehicle installation/uninstallation)

Definition at line 2737 of file character.cpp.

2738{
2739 const quality_id LIFT( "LIFT" );
2740 int mech_lift = 0;
2741 if( is_mounted() ) {
2742 auto mons = mounted_creature.get();
2743 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
2744 mech_lift = mons->mech_str_addition() + 10;
2745 }
2746 }
2747 return std::max( { this->max_quality( LIFT ), mech_lift,
2748 map_selector( this->pos(), PICKUP_RANGE, false ).max_quality( LIFT ),
2749 vehicle_selector( world_pos, PICKUP_RANGE, false ).max_quality( LIFT )
2750 } );
2751}
int PICKUP_RANGE
Items on the map with at most this distance to the player are considered available for crafting,...
shared_ptr_fast< monster > mounted_creature
Definition: character.h:1564
int max_quality(const quality_id &qual) const
Return maximum tool quality level provided by instance or INT_MIN if not found.
Definition: visitable.cpp:276
@ MF_RIDEABLE_MECH
Definition: mtype.h:115

References is_mounted(), visitable< T >::max_quality(), visitable< Character >::max_quality(), MF_RIDEABLE_MECH, mounted_creature, PICKUP_RANGE, and pos().

◆ best_quality_item()

item * Character::best_quality_item ( const quality_id qual)

get best quality item that this character has

Definition at line 4734 of file character.cpp.

4735{
4736 std::vector<item *> qual_inv = items_with( [qual]( const item & itm ) {
4737 return itm.has_quality( qual );
4738 } );
4739 item *best_qual = random_entry( qual_inv );
4740 for( const auto elem : qual_inv ) {
4741 if( elem->get_quality( qual ) > best_qual->get_quality( qual ) ) {
4742 best_qual = elem;
4743 }
4744 }
4745 return best_qual;
4746}
bool has_quality(const quality_id &qual, int level=1, int qty=1) const
Returns true if instance has amount (or more) items of at least quality level.
Definition: visitable.cpp:169

References visitable< T >::has_quality(), visitable< Character >::items_with(), and random_entry().

Referenced by chop_plank_activity(), chop_tree_activity(), and generic_multi_activity_do().

◆ best_shield()

item & Character::best_shield ( )

Returns the best item for blocking with.

Definition at line 1543 of file melee.cpp.

1544{
1545 // Note: wielded weapon, not one used for attacks
1546 int best_value = blocking_ability( weapon );
1547 // "BLOCK_WHILE_WORN" without a blocking tech need to be worn for the bonus
1548 best_value = best_value == 2 ? 0 : best_value;
1549 item *best = best_value > 0 ? &weapon : &null_item_reference();
1550 for( item &shield : worn ) {
1551 if( shield.has_flag( "BLOCK_WHILE_WORN" ) && blocking_ability( shield ) >= best_value ) {
1552 best = &shield;
1553 }
1554 }
1555
1556 return *best;
1557}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:321
static int blocking_ability(const item &shield)
Definition: melee.cpp:1528

References blocking_ability(), null_item_reference(), weapon, and worn.

Referenced by block_hit().

◆ bionic_armor_bonus()

float Character::bionic_armor_bonus ( const bodypart_id bp,
damage_type  dt 
) const

Check for passive bionics that provide armor, and returns the armor bonus This is called from player::passive_absorb_hit.

Definition at line 8371 of file character.cpp.

8372{
8373 float result = 0.0f;
8374 if( dt == DT_CUT || dt == DT_STAB ) {
8375 for( const bionic_id &bid : get_bionics() ) {
8376 const auto cut_prot = bid->cut_protec.find( bp.id() );
8377 if( cut_prot != bid->cut_protec.end() ) {
8378 result += cut_prot->second;
8379 }
8380 }
8381 } else if( dt == DT_BASH ) {
8382 for( const bionic_id &bid : get_bionics() ) {
8383 const auto bash_prot = bid->bash_protec.find( bp.id() );
8384 if( bash_prot != bid->bash_protec.end() ) {
8385 result += bash_prot->second;
8386 }
8387 }
8388 } else if( dt == DT_BULLET ) {
8389 for( const bionic_id &bid : get_bionics() ) {
8390 const auto bullet_prot = bid->bullet_protec.find( bp.id() );
8391 if( bullet_prot != bid->bullet_protec.end() ) {
8392 result += bullet_prot->second;
8393 }
8394 }
8395 }
8396
8397 return result;
8398}
const string_id< T > & id() const
Definition: ammo_effect.cpp:33

References bionic_data::bash_protec, bionic_data::bullet_protec, bionic_data::cut_protec, DT_BASH, DT_BULLET, DT_CUT, DT_STAB, get_bionics(), and int_id< T >::id().

Referenced by passive_absorb_hit().

◆ bionic_at_index()

bionic & Character::bionic_at_index ( int  i)

Returns the bionic at a given index in my_bionics[].

Definition at line 2661 of file bionics.cpp.

2662{
2663 return ( *my_bionics )[i];
2664}

References my_bionics.

Referenced by absorb_hit(), and sleep().

◆ bionic_installation_issues()

std::map< bodypart_id, int > Character::bionic_installation_issues ( const bionic_id bioid) const

Definition at line 2507 of file bionics.cpp.

2508{
2509 std::map<bodypart_id, int> issues;
2510 if( !get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
2511 return issues;
2512 }
2513 for( const std::pair<const bodypart_str_id, int> &elem : bioid->occupied_bodyparts ) {
2514 const int lacked_slots = elem.second - get_free_bionics_slots( elem.first );
2515 if( lacked_slots > 0 ) {
2516 issues.emplace( elem.first, lacked_slots );
2517 }
2518 }
2519 return issues;
2520}
int get_free_bionics_slots(const bodypart_id &bp) const
Definition: bionics.cpp:2527
std::map< bodypart_str_id, int > occupied_bodyparts
Body part slots used to install this bionic, mapped to the amount of space required.
Definition: bionics.h:89

References get_free_bionics_slots(), and bionic_data::occupied_bodyparts.

Referenced by can_install_bionics(), and item::color_in_inventory().

◆ bionics_adjusted_skill()

float Character::bionics_adjusted_skill ( const skill_id most_important_skill,
const skill_id important_skill,
const skill_id least_important_skill,
int  skill_level = -1 
)

Calculate skill for (un)installing bionics.

Definition at line 1846 of file bionics.cpp.

1850{
1851 int pl_skill = bionics_pl_skill( most_important_skill, important_skill, least_important_skill,
1852 skill_level );
1853
1854 // for chance_of_success calculation, shift skill down to a float between ~0.4 - 30
1855 float adjusted_skill = static_cast<float>( pl_skill ) - std::min( static_cast<float>( 40 ),
1856 static_cast<float>( pl_skill ) - static_cast<float>( pl_skill ) / static_cast<float>( 10.0 ) );
1857 adjusted_skill *= env_surgery_bonus( 1 ) + get_effect_int( effect_assisted );
1858 return adjusted_skill;
1859}
static const efftype_id effect_assisted("assisted")
float env_surgery_bonus(int radius)
Calculate skill bonus from tiles in radius.
Definition: bionics.cpp:2239
int bionics_pl_skill(const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
Calculate non adjusted skill for (un)installing bionics.
Definition: bionics.cpp:1861
int get_effect_int(const efftype_id &eff_id, body_part bp=num_bp) const
Returns the intensity of the matching effect.
Definition: creature.cpp:1250

References bionics_pl_skill(), effect_assisted, env_surgery_bonus(), and Creature::get_effect_int().

Referenced by best_installer(), can_install_bionics(), can_uninstall_bionic(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), install_bionics(), game::save_cyborg(), and uninstall_bionic().

◆ bionics_install_failure()

void Character::bionics_install_failure ( const std::string &  installer,
int  difficulty,
int  success,
float  adjusted_skill 
)

Definition at line 2400 of file bionics.cpp.

2402{
2403 // "success" should be passed in as a negative integer representing how far off we
2404 // were for a successful install. We use this to determine consequences for failing.
2405 success = std::abs( success );
2406
2407 // failure level is decided by how far off the character was from a successful install, and
2408 // this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
2409 // difficulties), only minor consequences occur. At low skill levels, severe consequences
2410 // are more likely.
2411 int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty / adjusted_skill ) );
2412 int fail_type = ( failure_level > 5 ? 5 : failure_level );
2413
2414 if( installer != "NOT_MED" ) {
2415 //~"Complications" is USian medical-speak for "unintended damage from a medical procedure".
2416 add_msg( m_neutral, _( "%s training helps to minimize the complications." ),
2417 installer );
2418 // In addition to the bonus, medical residents know enough OR protocol to avoid botching.
2419 // Take MD and be immune to faulty bionics.
2420 if( fail_type > 3 ) {
2421 fail_type = rng( 1, 3 );
2422 }
2423 }
2424
2425 switch( fail_type ) {
2426 case 0:
2427 case 1:
2429 break;
2430 case 2:
2431 case 3:
2432 do_damage_for_bionic_failure( 5, difficulty * 5 );
2433 break;
2434 case 4:
2435 case 5: {
2436 std::vector<bionic_id> valid;
2437 std::copy_if( begin( faulty_bionics ), end( faulty_bionics ), std::back_inserter( valid ),
2438 [&]( const bionic_id & id ) {
2439 return !has_bionic( id );
2440 } );
2441
2442 // We've got all the bad bionics!
2443 if( valid.empty() ) {
2444 if( has_max_power() ) {
2445 units::energy old_power = get_max_power_level();
2446 add_msg( m_bad, _( "%s lose power capacity!" ), disp_name() );
2451 }
2452 if( is_player() ) {
2453 g->memorial().add(
2454 pgettext( "memorial_male", "Lost %d units of power capacity." ),
2455 pgettext( "memorial_female", "Lost %d units of power capacity." ),
2456 units::to_kilojoule( old_power - get_max_power_level() ) );
2457 }
2458 // If no faults available and no power capacity, downgrade to second-worst complication.
2459 } else {
2460 do_damage_for_bionic_failure( 5, difficulty * 5 );
2461 break;
2462 }
2463 } else {
2464 const bionic_id &id = random_entry( valid );
2465 add_bionic( id );
2466 g->events().send<event_type::installs_faulty_cbm>( getID(), id );
2467 add_msg( m_bad,
2468 _( "Complication in installation caused a malfunction - %s. Uninstall it to clear the malfunction." ),
2469 id.obj().name );
2470 }
2471 }
2472 break;
2473 }
2474
2475}
bool has_max_power() const
Definition: character.cpp:2017
void set_max_power_level(const units::energy &npower_max)
Definition: character.cpp:1985
void do_damage_for_bionic_failure(int min_damage, int max_damage)
Definition: bionics.cpp:2360
@ installs_faulty_cbm
std::vector< bionic_id > faulty_bionics
Definition: bionics.cpp:216
const char * pgettext(const char *context, const char *msgid)

References _, add_bionic(), add_msg(), disp_name(), do_damage_for_bionic_failure(), anonymous_namespace{bionics.cpp}::faulty_bionics, units::from_kilojoule(), g, get_max_power_level(), getID(), has_bionic(), has_max_power(), id, installs_faulty_cbm, Creature::is_player(), m_bad, m_neutral, name, pgettext(), random_entry(), rng(), set_max_power_level(), behavior::success, and units::to_kilojoule().

Referenced by perform_install().

◆ bionics_pl_skill()

int Character::bionics_pl_skill ( const skill_id most_important_skill,
const skill_id important_skill,
const skill_id least_important_skill,
int  skill_level = -1 
)

Calculate non adjusted skill for (un)installing bionics.

Definition at line 1861 of file bionics.cpp.

1864{
1865 int pl_skill;
1866 if( skill_level == -1 ) {
1867 pl_skill = int_cur * 4 +
1868 get_skill_level( most_important_skill ) * 4 +
1869 get_skill_level( important_skill ) * 3 +
1870 get_skill_level( least_important_skill ) * 1;
1871 } else {
1872 // override chance as though all values were skill_level if it is provided
1873 pl_skill = 12 * skill_level;
1874 }
1875
1876 // Medical residents have some idea what they're doing
1877 if( has_trait( trait_PROF_MED ) ) {
1878 pl_skill += 3;
1879 }
1880
1881 // People trained in bionics gain an additional advantage towards using it
1882 if( has_trait( trait_PROF_AUTODOC ) ) {
1883 pl_skill += 7;
1884 }
1885 return pl_skill;
1886}
static const trait_id trait_PROF_MED("PROF_MED")
static const trait_id trait_PROF_AUTODOC("PROF_AUTODOC")

References get_skill_level(), has_trait(), int_cur, trait_PROF_AUTODOC, and trait_PROF_MED.

Referenced by bionics_adjusted_skill(), install_bionics(), and uninstall_bionic().

◆ bionics_uninstall_failure() [1/2]

void Character::bionics_uninstall_failure ( int  difficulty,
int  success,
float  adjusted_skill 
)

When a player fails the surgery.

Definition at line 1737 of file bionics.cpp.

1738{
1739 // "success" should be passed in as a negative integer representing how far off we
1740 // were for a successful removal. We use this to determine consequences for failing.
1741 success = std::abs( success );
1742
1743 // failure level is decided by how far off the character was from a successful removal, and
1744 // this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
1745 // difficulties), only minor consequences occur. At low skill levels, severe consequences
1746 // are more likely.
1747 const int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty /
1748 adjusted_skill ) );
1749 const int fail_type = std::min( 5, failure_level );
1750
1751 if( fail_type <= 1 ) {
1752 add_msg( m_neutral, _( "The removal fails without incident." ) );
1753 return;
1754 }
1755
1756 add_msg( m_neutral, _( "The removal is a failure." ) );
1757 std::set<body_part> bp_hurt;
1758 switch( fail_type ) {
1759 case 2:
1760 case 3:
1762 break;
1763
1764 case 4:
1765 case 5:
1766 do_damage_for_bionic_failure( 5, difficulty * 5 );
1767 break;
1768 }
1769
1770}

References _, add_msg(), do_damage_for_bionic_failure(), m_neutral, and behavior::success.

Referenced by perform_uninstall(), and uninstall_bionic().

◆ bionics_uninstall_failure() [2/2]

void Character::bionics_uninstall_failure ( monster installer,
player patient,
int  difficulty,
int  success,
float  adjusted_skill 
)

When a monster fails the surgery.

Definition at line 1772 of file bionics.cpp.

1774{
1775
1776 // "success" should be passed in as a negative integer representing how far off we
1777 // were for a successful removal. We use this to determine consequences for failing.
1778 success = std::abs( success );
1779
1780 // failure level is decided by how far off the monster was from a successful removal, and
1781 // this is scaled up or down by the ratio of difficulty/skill. At high skill levels (or low
1782 // difficulties), only minor consequences occur. At low skill levels, severe consequences
1783 // are more likely.
1784 const int failure_level = static_cast<int>( std::sqrt( success * 4.0 * difficulty /
1785 adjusted_skill ) );
1786 const int fail_type = std::min( 5, failure_level );
1787
1788 bool u_see = sees( patient );
1789
1790 if( u_see || patient.is_player() ) {
1791 if( fail_type <= 1 ) {
1792 add_msg( m_neutral, _( "The removal fails without incident." ) );
1793 return;
1794 }
1795 switch( rng( 1, 5 ) ) {
1796 case 1:
1797 add_msg( m_mixed, _( "The %s flub the operation." ), installer.name() );
1798 break;
1799 case 2:
1800 add_msg( m_mixed, _( "The %s messes up the operation." ), installer.name() );
1801 break;
1802 case 3:
1803 add_msg( m_mixed, _( "The operation fails." ) );
1804 break;
1805 case 4:
1806 add_msg( m_mixed, _( "The operation is a failure." ) );
1807 break;
1808 case 5:
1809 add_msg( m_mixed, _( "The %s screws up the operation." ), installer.name() );
1810 break;
1811 }
1812 }
1813 switch( fail_type ) {
1814 case 2:
1815 case 3:
1816 do_damage_for_bionic_failure( failure_level, failure_level * 2 );
1817 break;
1818
1819 case 4:
1820 case 5:
1821 do_damage_for_bionic_failure( 5, difficulty * 5 );
1822 break;
1823 }
1824}
bool sees(const tripoint &t, bool is_player=false, int range_mod=0) const override
std::string name(unsigned int quantity=1) const
Definition: monster.cpp:492
bool is_player() const override
Definition: player.h:105

References _, add_msg(), do_damage_for_bionic_failure(), player::is_player(), m_mixed, m_neutral, monster::name(), rng(), sees(), and behavior::success.

◆ bionics_weight()

units::mass Character::bionics_weight ( ) const

Definition at line 6883 of file character.cpp.

6884{
6885 units::mass bio_weight = 0_gram;
6886 for( const bionic_id &bid : get_bionics() ) {
6887 if( !bid->included ) {
6888 bio_weight += bid->itype()->weight;
6889 }
6890 }
6891 return bio_weight;
6892}

References get_bionics().

Referenced by get_weight().

◆ block_hit()

bool Character::block_hit ( Creature source,
bodypart_id bp_hit,
damage_instance dam 
)
overridevirtual

Checks for valid block abilities and reduces damage accordingly.

Returns true if the player blocks

Strength increases attack blocking effectiveness with a limb or worn/wielded item Unarmed increases attack blocking effectiveness with a limb or worn/wielded item

Implements Creature.

Definition at line 1559 of file melee.cpp.

1560{
1561 // Shouldn't block if player is asleep
1563 return false;
1564 }
1565
1566 // fire martial arts on-getting-hit-triggered effects
1567 // these fire even if the attack is blocked (you still got hit)
1568 martial_arts_data->ma_ongethit_effects( *this );
1569
1570 if( blocks_left < 1 ) {
1571 return false;
1572 }
1573
1574 blocks_left--;
1575
1576 // This bonus absorbs damage from incoming attacks before they land,
1577 // but it still counts as a block even if it absorbs all the damage.
1578 float total_phys_block = mabuff_block_bonus();
1579
1580 // Extract this to make it easier to implement shields/multiwield later
1581 item &shield = best_shield();
1582 block_bonus = blocking_ability( shield );
1583 bool conductive_shield = shield.conductive();
1584 bool unarmed = weapon.has_flag( "UNARMED_WEAPON" );
1585 bool force_unarmed = martial_arts_data->is_force_unarmed();
1586
1587 int melee_skill = get_skill_level( skill_melee );
1588 int unarmed_skill = get_skill_level( skill_unarmed );
1589
1590 // Check if we are going to block with an item. This could
1591 // be worn equipment with the BLOCK_WHILE_WORN flag.
1592 const bool has_shield = !shield.is_null();
1593
1594 // boolean check if blocking is being done with unarmed or not
1595 const bool item_blocking = !force_unarmed && has_shield && !unarmed;
1596
1597 int block_score = 1;
1598
1599 /** @EFFECT_STR increases attack blocking effectiveness with a limb or worn/wielded item */
1600 /** @EFFECT_UNARMED increases attack blocking effectiveness with a limb or worn/wielded item */
1601 if( ( unarmed || force_unarmed ) ) {
1602 if( martial_arts_data->can_limb_block( *this ) ) {
1603 // block_bonus for limb blocks will be added when the limb is decided
1604 block_score = str_cur + melee_skill + unarmed_skill;
1605 } else if( has_shield ) {
1606 // We can still block with a worn item while unarmed. Use higher of melee and unarmed
1607 block_score = str_cur + block_bonus + std::max( melee_skill, unarmed_skill );
1608 }
1609 } else if( has_shield ) {
1610 block_score = str_cur + block_bonus + get_skill_level( skill_melee );
1611 } else {
1612 // Can't block with limbs or items (do not block)
1613 return false;
1614 }
1615
1616 // weapon blocks are preferred to limb blocks
1617 std::string thing_blocked_with;
1618 if( !force_unarmed && has_shield ) {
1619 thing_blocked_with = shield.tname();
1620 // TODO: Change this depending on damage blocked
1621 float wear_modifier = 1.0f;
1622 if( source != nullptr && source->is_hallucination() ) {
1623 wear_modifier = 0.0f;
1624 }
1625
1626 handle_melee_wear( shield, wear_modifier );
1627 } else {
1628 //Choose which body part to block with, assume left side first
1629 if( martial_arts_data->can_leg_block( *this ) && martial_arts_data->can_arm_block( *this ) ) {
1630 bp_hit = one_in( 2 ) ? bodypart_id( "leg_l" ) : bodypart_id( "arm_l" );
1631 } else if( martial_arts_data->can_leg_block( *this ) ) {
1632 bp_hit = bodypart_id( "leg_l" );
1633 } else {
1634 bp_hit = bodypart_id( "arm_l" );
1635 }
1636
1637 // Check if we should actually use the right side to block
1638 if( bp_hit == bodypart_id( "leg_l" ) ) {
1639 if( get_part_hp_cur( bodypart_id( "leg_r" ) ) > get_part_hp_cur( bodypart_id( "leg_l" ) ) ) {
1640 bp_hit = bodypart_id( "leg_r" );
1641 }
1642 } else {
1643 if( get_part_hp_cur( bodypart_id( "arm_r" ) ) > get_part_hp_cur( bodypart_id( "arm_l" ) ) ) {
1644 bp_hit = bodypart_id( "arm_r" );
1645 }
1646 }
1647
1648 thing_blocked_with = body_part_name( bp_hit->token );
1649 }
1650
1651 if( has_shield ) {
1652 // Does our shield cover the limb we blocked with? If so, add the block bonus.
1653 block_score += shield.covers( bp_hit->token ) ? block_bonus : 0;
1654 }
1655
1656 // Map block_score to the logistic curve for a number between 1 and 0.
1657 // Basic beginner character (str 8, skill 0, basic weapon)
1658 // Will have a score around 10 and block about %15 of incoming damage.
1659 // More proficient melee character (str 10, skill 4, wbock_2 weapon)
1660 // will have a score of 20 and block about 45% of damage.
1661 // A highly expert character (str 14, skill 8 wblock_2)
1662 // will have a score in the high 20s and will block about 80% of damage.
1663 // As the block score approaches 40, damage making it through will dwindle
1664 // to nothing, at which point we're relying on attackers hitting enough to drain blocks.
1665 const float physical_block_multiplier = logarithmic_range( 0, 40, block_score );
1666
1667 float total_damage = 0.0;
1668 float damage_blocked = 0.0;
1669
1670 for( auto &elem : dam.damage_units ) {
1671 total_damage += elem.amount;
1672
1673 // block physical damage "normally"
1674 if( elem.type == DT_BASH || elem.type == DT_CUT || elem.type == DT_STAB ) {
1675 // use up our flat block bonus first
1676 float block_amount = std::min( total_phys_block, elem.amount );
1677 total_phys_block -= block_amount;
1678 elem.amount -= block_amount;
1679 damage_blocked += block_amount;
1680
1681 if( elem.amount <= std::numeric_limits<float>::epsilon() ) {
1682 continue;
1683 }
1684
1685 float previous_amount = elem.amount;
1686 elem.amount *= physical_block_multiplier;
1687 damage_blocked += previous_amount - elem.amount;
1688 }
1689
1690 // non-electrical "elemental" damage types do their full damage if unarmed,
1691 // but severely mitigated damage if not
1692 else if( elem.type == DT_HEAT || elem.type == DT_ACID || elem.type == DT_COLD ) {
1693 // Unarmed weapons won't block those
1694 if( item_blocking ) {
1695 float previous_amount = elem.amount;
1696 elem.amount /= 5;
1697 damage_blocked += previous_amount - elem.amount;
1698 }
1699 // electrical damage deals full damage if unarmed OR wielding a
1700 // conductive weapon
1701 } else if( elem.type == DT_ELECTRIC ) {
1702 // Unarmed weapons and conductive weapons won't block this
1703 if( item_blocking && !conductive_shield ) {
1704 float previous_amount = elem.amount;
1705 elem.amount /= 5;
1706 damage_blocked += previous_amount - elem.amount;
1707 }
1708 }
1709 }
1710
1711 std::string damage_blocked_description;
1712 // good/bad/ugly add_msg color code?
1713 // none, hardly any, a little, some, most, all
1714 float blocked_ratio = 0.0f;
1715 if( total_damage > std::numeric_limits<float>::epsilon() ) {
1716 blocked_ratio = ( total_damage - damage_blocked ) / total_damage;
1717 }
1718 if( blocked_ratio < std::numeric_limits<float>::epsilon() ) {
1719 //~ Damage amount in "You block <damage amount> with your <weapon>."
1720 damage_blocked_description = pgettext( "block amount", "all of the damage" );
1721 } else if( blocked_ratio < 0.2 ) {
1722 //~ Damage amount in "You block <damage amount> with your <weapon>."
1723 damage_blocked_description = pgettext( "block amount", "nearly all of the damage" );
1724 } else if( blocked_ratio < 0.4 ) {
1725 //~ Damage amount in "You block <damage amount> with your <weapon>."
1726 damage_blocked_description = pgettext( "block amount", "most of the damage" );
1727 } else if( blocked_ratio < 0.6 ) {
1728 //~ Damage amount in "You block <damage amount> with your <weapon>."
1729 damage_blocked_description = pgettext( "block amount", "a lot of the damage" );
1730 } else if( blocked_ratio < 0.8 ) {
1731 //~ Damage amount in "You block <damage amount> with your <weapon>."
1732 damage_blocked_description = pgettext( "block amount", "some of the damage" );
1733 } else if( blocked_ratio > std::numeric_limits<float>::epsilon() ) {
1734 //~ Damage amount in "You block <damage amount> with your <weapon>."
1735 damage_blocked_description = pgettext( "block amount", "a little of the damage" );
1736 } else {
1737 //~ Damage amount in "You block <damage amount> with your <weapon>."
1738 damage_blocked_description = pgettext( "block amount", "none of the damage" );
1739 }
1741 //~ %1$s is damage amount string (e.g. "most of the damage"), %2$s is weapon name
1742 _( "You block %1$s with your %2$s!" ),
1743 //~ %1$s is damage amount string (e.g. "most of the damage"), %2$s is weapon name
1744 _( "<npcname> blocks %1$s with their %2$s!" ),
1745 damage_blocked_description, thing_blocked_with );
1746
1747 // fire martial arts block-triggered effects
1748 martial_arts_data->ma_onblock_effects( *this );
1749
1750 // Check if we have any block counters
1751 matec_id tec = pick_technique( *source, shield, false, false, true );
1752
1753 if( tec != tec_none && !is_dead_state() ) {
1754 if( get_stamina() < get_stamina_max() / 3 ) {
1755 add_msg( m_bad, _( "You try to counterattack but you are too exhausted!" ) );
1756 } else if( weapon.made_of( material_id( "glass" ) ) ) {
1757 add_msg( m_bad, _( "The item you are wielding is too fragile to counterattack with!" ) );
1758 } else {
1759 melee_attack( *source, false, tec );
1760 }
1761 }
1762
1763 return true;
1764}
std::string body_part_name(body_part bp, int number)
Returns the matching name of the body_part token.
Definition: bodypart.cpp:317
int blocks_left
Definition: character.h:557
matec_id pick_technique(Creature &t, const item &weap, bool crit, bool dodge_counter, bool block_counter)
Returns a random valid technique.
Definition: melee.cpp:1114
int mabuff_block_bonus() const
Returns the block bonus from martial arts buffs.
bool in_sleep_state() const override
Definition: character.cpp:9334
void melee_attack(Creature &t, bool allow_special, const matec_id &force_technique, bool allow_unarmed=true)
Sets up a melee attack and handles melee attack function calls.
Definition: melee.cpp:390
bool handle_melee_wear(item &shield, float wear_multiplier=1.0f)
Calculates melee weapon wear-and-tear through use, returns true if item is destroyed.
Definition: melee.cpp:156
item & best_shield()
Returns the best item for blocking with.
Definition: melee.cpp:1543
virtual bool is_hallucination() const =0
virtual void add_msg_player_or_npc(const std::string &, const std::string &) const
Definition: creature.h:677
int block_bonus
Definition: creature.h:827
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6322
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6257
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_ACID
Definition: damage.h:26
static const efftype_id effect_narcosis("narcosis")
static const matec_id tec_none("tec_none")
static const skill_id skill_unarmed("unarmed")

References _, add_msg(), Creature::add_msg_player_or_npc(), best_shield(), Creature::block_bonus, blocking_ability(), blocks_left, body_part_name(), item::conductive(), item::covers(), damage_instance::damage_units, DT_ACID, DT_BASH, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_STAB, effect_narcosis, Creature::get_part_hp_cur(), get_skill_level(), get_stamina(), get_stamina_max(), handle_melee_wear(), Creature::has_effect(), item::has_flag(), in_sleep_state(), Creature::is_dead_state(), Creature::is_hallucination(), item::is_null(), logarithmic_range(), m_bad, mabuff_block_bonus(), item::made_of(), martial_arts_data, melee_attack(), one_in(), pgettext(), pick_technique(), skill_melee, skill_unarmed, str_cur, tec_none, item::tname(), and weapon.

◆ blood_loss()

int Character::blood_loss ( const bodypart_id bp) const

Define blood loss (in percents)

Definition at line 5833 of file character.cpp.

5834{
5835 int hp_cur_sum = get_part_hp_cur( bp );
5836 int hp_max_sum = get_part_hp_max( bp );
5837
5838 if( bp == bodypart_id( "leg_l" ) || bp == bodypart_id( "leg_r" ) ) {
5839 hp_cur_sum = get_part_hp_cur( bodypart_id( "leg_l" ) ) + get_part_hp_cur( bodypart_id( "leg_r" ) );
5840 hp_max_sum = get_part_hp_max( bodypart_id( "leg_l" ) ) + get_part_hp_max( bodypart_id( "leg_r" ) );
5841 } else if( bp == bodypart_id( "arm_l" ) || bp == bodypart_id( "arm_r" ) ) {
5842 hp_cur_sum = get_part_hp_cur( bodypart_id( "arm_l" ) ) + get_part_hp_cur( bodypart_id( "arm_r" ) );
5843 hp_max_sum = get_part_hp_max( bodypart_id( "arm_l" ) ) + get_part_hp_max( bodypart_id( "arm_r" ) );
5844 }
5845
5846 hp_cur_sum = std::min( hp_max_sum, std::max( 0, hp_cur_sum ) );
5847 hp_max_sum = std::max( hp_max_sum, 1 );
5848 return 100 - ( 100 * hp_cur_sum ) / hp_max_sum;
5849}
int get_part_hp_max(const bodypart_id &id) const
Definition: creature.cpp:1565

References Creature::get_part_hp_cur(), and Creature::get_part_hp_max().

◆ bloodType()

field_type_id Character::bloodType ( ) const
overridevirtual

Implements Creature.

Definition at line 482 of file character.cpp.

483{
484 if( has_trait( trait_ACIDBLOOD ) ) {
485 return fd_acid;
486 }
488 return fd_blood_veggy;
489 }
491 return fd_blood_insect;
492 }
495 }
496 return fd_blood;
497}
static const trait_id trait_THRESH_CEPHALOPOD("THRESH_CEPHALOPOD")
static const trait_id trait_THRESH_PLANT("THRESH_PLANT")
static const trait_id trait_THRESH_INSECT("THRESH_INSECT")
static const trait_id trait_ACIDBLOOD("ACIDBLOOD")
field_type_id fd_blood_insect
Definition: field_type.cpp:363
field_type_id fd_blood_invertebrate
Definition: field_type.cpp:364
field_type_id fd_blood_veggy
Definition: field_type.cpp:362
field_type_id fd_blood
Definition: field_type.cpp:336
field_type_id fd_acid
Definition: field_type.cpp:342

References fd_acid, fd_blood, fd_blood_insect, fd_blood_invertebrate, fd_blood_veggy, has_trait(), trait_ACIDBLOOD, trait_THRESH_CEPHALOPOD, trait_THRESH_INSECT, trait_THRESH_PLANT, and trait_THRESH_SPIDER.

◆ blossoms()

void Character::blossoms ( )

Definition at line 8804 of file character.cpp.

8805{
8806 // Player blossoms are shorter-ranged, but you can fire much more frequently if you like.
8807 sounds::sound( pos(), 10, sounds::sound_t::combat, _( "Pouf!" ), false, "misc", "puff" );
8808 map &here = get_map();
8809 for( const tripoint &tmp : here.points_in_radius( pos(), 2 ) ) {
8810 here.add_field( tmp, fd_fungal_haze, rng( 1, 2 ) );
8811 }
8812}
field_type_id fd_fungal_haze
Definition: field_type.cpp:374

References _, map::add_field(), sounds::combat, fd_fungal_haze, get_map(), map::points_in_radius(), pos(), rng(), and sounds::sound().

Referenced by activate_mutation(), and suffer_while_awake().

◆ bmi()

float Character::bmi ( ) const

Definition at line 6873 of file character.cpp.

6874{
6875 return 25;
6876}

Referenced by bodyweight(), debug_menu::debug(), character_display::disp_info(), and suffer_mutation_power().

◆ bmr()

int Character::bmr ( ) const

Definition at line 6980 of file character.cpp.

6981{
6982 return metabolic_rate_base() * 2500;
6983}
float metabolic_rate_base() const
Stable base metabolic rate due to traits.

References metabolic_rate_base().

Referenced by debug_menu::debug(), fall_asleep(), get_hunger_description(), and update_stomach().

◆ body_window()

hp_part Character::body_window ( const std::string &  menu_header,
bool  show_all,
bool  precise,
int  normal_bonus,
int  head_bonus,
int  torso_bonus,
float  bleed,
float  bite,
float  infect,
float  bandage_power,
float  disinfectant_power 
) const

Displays menu with body part hp, optionally with hp estimation after healing.

Returns selected part. menu_header - name of item that triggers this menu show_all - show and enable choice of all limbs, not only healable precise - show numerical hp normal_bonus - heal normal limb head_bonus - heal head torso_bonus - heal torso bleed - chance to stop bleeding bite - chance to remove bite infect - chance to remove infection bandage_power - quality of bandage disinfectant_power - quality of disinfectant

Definition at line 5863 of file character.cpp.

5867{
5868 /* This struct establishes some kind of connection between the hp_part (which can be healed and
5869 * have HP) and the body_part. Note that there are more body_parts than hp_parts. For example:
5870 * Damage to bp_head, bp_eyes and bp_mouth is all applied on the HP of hp_head. */
5871 struct healable_bp {
5872 mutable bool allowed;
5873 bodypart_id bp;
5874 hp_part hp;
5875 std::string name; // Translated name as it appears in the menu.
5876 int bonus;
5877 };
5878 /* The array of the menu entries show to the player. The entries are displayed in this order,
5879 * it may be changed here. */
5880 std::array<healable_bp, num_hp_parts> parts = { {
5881 { false, bodypart_id( "head" ), hp_head, _( "Head" ), head_bonus },
5882 { false, bodypart_id( "torso" ), hp_torso, _( "Torso" ), torso_bonus },
5883 { false, bodypart_id( "arm_l" ), hp_arm_l, _( "Left Arm" ), normal_bonus },
5884 { false, bodypart_id( "arm_r" ), hp_arm_r, _( "Right Arm" ), normal_bonus },
5885 { false, bodypart_id( "leg_l" ), hp_leg_l, _( "Left Leg" ), normal_bonus },
5886 { false, bodypart_id( "leg_r" ), hp_leg_r, _( "Right Leg" ), normal_bonus },
5887 }
5888 };
5889
5890 int max_bp_name_len = 0;
5891 for( const auto &e : parts ) {
5892 max_bp_name_len = std::max( max_bp_name_len, utf8_width( e.name ) );
5893 }
5894
5895 uilist bmenu;
5896 bmenu.desc_enabled = true;
5897 bmenu.text = menu_header;
5898
5899 bmenu.hilight_disabled = true;
5900 bool is_valid_choice = false;
5901
5902 for( size_t i = 0; i < parts.size(); i++ ) {
5903 const auto &e = parts[i];
5904 const bodypart_id &bp = e.bp;
5905 const body_part bp_token = bp->token;
5906 const int maximal_hp = get_part_hp_max( bp );
5907 const int current_hp = get_part_hp_cur( bp );
5908 // This will c_light_gray if the part does not have any effects cured by the item/effect
5909 // (e.g. it cures only bites, but the part does not have a bite effect)
5910 const nc_color state_col = limb_color( bp, bleed > 0.0f, bite > 0.0f, infect > 0.0f );
5911 const bool has_curable_effect = state_col != c_light_gray;
5912 // The same as in the main UI sidebar. Independent of the capability of the healing item/effect!
5913 const nc_color all_state_col = limb_color( bp, true, true, true );
5914 // Broken means no HP can be restored, it requires surgical attention.
5915 const bool limb_is_broken = is_limb_broken( bp );
5916 const bool limb_is_mending = limb_is_broken && worn_with_flag( flag_SPLINT, bp );
5917
5918 if( show_all ) {
5919 e.allowed = true;
5920 } else if( has_curable_effect ) {
5921 e.allowed = true;
5922 } else if( limb_is_broken ) {
5923 e.allowed = false;
5924 } else if( current_hp < maximal_hp && ( e.bonus != 0 || bandage_power > 0.0f ||
5925 disinfectant_power > 0.0f ) ) {
5926 e.allowed = true;
5927 } else {
5928 e.allowed = false;
5929 }
5930
5931 std::string msg;
5932 std::string desc;
5933 bool bleeding = has_effect( effect_bleed, bp_token );
5934 bool bitten = has_effect( effect_bite, bp_token );
5935 bool infected = has_effect( effect_infected, bp_token );
5936 bool bandaged = has_effect( effect_bandaged, bp_token );
5937 bool disinfected = has_effect( effect_disinfected, bp_token );
5938 const int b_power = get_effect_int( effect_bandaged, bp_token );
5939 const int d_power = get_effect_int( effect_disinfected, bp_token );
5940 int new_b_power = static_cast<int>( std::floor( bandage_power ) );
5941 if( bandaged ) {
5942 const effect &eff = get_effect( effect_bandaged, bp_token );
5943 if( new_b_power > eff.get_max_intensity() ) {
5944 new_b_power = eff.get_max_intensity();
5945 }
5946
5947 }
5948 int new_d_power = static_cast<int>( std::floor( disinfectant_power ) );
5949
5950 const auto &aligned_name = std::string( max_bp_name_len - utf8_width( e.name ), ' ' ) + e.name;
5951 std::string hp_str;
5952 if( limb_is_mending ) {
5953 desc += colorize( _( "It is broken but has been set and just needs time to heal." ),
5954 c_blue ) + "\n";
5955 const auto &eff = get_effect( effect_mending, bp_token );
5956 const int mend_perc = eff.is_null() ? 0.0 : 100 * eff.get_duration() / eff.get_max_duration();
5957
5958 if( precise ) {
5959 hp_str = colorize( string_format( "=%2d%%=", mend_perc ), c_blue );
5960 } else {
5961 const int num = mend_perc / 20;
5962 hp_str = colorize( std::string( num, '#' ) + std::string( 5 - num, '=' ), c_blue );
5963 }
5964 } else if( limb_is_broken ) {
5965 desc += colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) + "\n";
5966 hp_str = "==%==";
5967 } else if( precise ) {
5968 hp_str = string_format( "%d", current_hp );
5969 } else {
5970 std::pair<std::string, nc_color> h_bar = get_hp_bar( current_hp, maximal_hp, false );
5971 hp_str = colorize( h_bar.first, h_bar.second ) +
5972 colorize( std::string( 5 - utf8_width( h_bar.first ), '.' ), c_white );
5973 }
5974 msg += colorize( aligned_name, all_state_col ) + " " + hp_str;
5975
5976 // BLEEDING block
5977 if( bleeding ) {
5978 desc += colorize( string_format( "%s: %s", get_effect( effect_bleed, bp_token ).get_speed_name(),
5979 get_effect( effect_bleed, bp_token ).disp_short_desc() ), c_red ) + "\n";
5980 if( bleed > 0.0f ) {
5981 desc += colorize( string_format( _( "Chance to stop: %d %%" ),
5982 static_cast<int>( bleed * 100 ) ), c_light_green ) + "\n";
5983 } else {
5984 desc += colorize( _( "This will not stop the bleeding." ),
5985 c_yellow ) + "\n";
5986 }
5987 }
5988 // BANDAGE block
5989 if( bandaged ) {
5990 desc += string_format( _( "Bandaged [%s]" ), texitify_healing_power( b_power ) ) + "\n";
5991 if( new_b_power > b_power ) {
5992 desc += colorize( string_format( _( "Expected quality improvement: %s" ),
5993 texitify_healing_power( new_b_power ) ), c_light_green ) + "\n";
5994 } else if( new_b_power > 0 ) {
5995 desc += colorize( _( "You don't expect any improvement from using this." ), c_yellow ) + "\n";
5996 }
5997 } else if( new_b_power > 0 && e.allowed ) {
5998 desc += colorize( string_format( _( "Expected bandage quality: %s" ),
5999 texitify_healing_power( new_b_power ) ), c_light_green ) + "\n";
6000 }
6001 // BITTEN block
6002 if( bitten ) {
6003 desc += colorize( string_format( "%s: ", get_effect( effect_bite,
6004 bp_token ).get_speed_name() ), c_red );
6005 desc += colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) + "\n";
6006 if( bite > 0 ) {
6007 desc += colorize( string_format( _( "Chance to clean and disinfect: %d %%" ),
6008 static_cast<int>( bite * 100 ) ), c_light_green ) + "\n";
6009 } else {
6010 desc += colorize( _( "This will not help in cleaning this wound." ), c_yellow ) + "\n";
6011 }
6012 }
6013 // INFECTED block
6014 if( infected ) {
6016 bp_token ).get_speed_name() ), c_red );
6017 desc += colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ),
6018 c_red ) + "\n";
6019 if( infect > 0 ) {
6020 desc += colorize( string_format( _( "Chance to heal infection: %d %%" ),
6021 static_cast<int>( infect * 100 ) ), c_light_green ) + "\n";
6022 } else {
6023 desc += colorize( _( "This will not help in healing infection." ), c_yellow ) + "\n";
6024 }
6025 }
6026 // DISINFECTANT (general) block
6027 if( disinfected ) {
6028 desc += string_format( _( "Disinfected [%s]" ),
6029 texitify_healing_power( d_power ) ) + "\n";
6030 if( new_d_power > d_power ) {
6031 desc += colorize( string_format( _( "Expected quality improvement: %s" ),
6032 texitify_healing_power( new_d_power ) ), c_light_green ) + "\n";
6033 } else if( new_d_power > 0 ) {
6034 desc += colorize( _( "You don't expect any improvement from using this." ),
6035 c_yellow ) + "\n";
6036 }
6037 } else if( new_d_power > 0 && e.allowed ) {
6038 desc += colorize( string_format(
6039 _( "Expected disinfection quality: %s" ),
6040 texitify_healing_power( new_d_power ) ), c_light_green ) + "\n";
6041 }
6042 // END of blocks
6043
6044 if( ( !e.allowed && !limb_is_broken ) || ( show_all && current_hp == maximal_hp &&
6045 !limb_is_broken && !bitten && !infected && !bleeding ) ) {
6046 desc += colorize( _( "Healthy." ), c_green ) + "\n";
6047 }
6048 if( !e.allowed ) {
6049 desc += colorize( _( "You don't expect any effect from using this." ), c_yellow );
6050 } else {
6051 is_valid_choice = true;
6052 }
6053 bmenu.addentry_desc( i, e.allowed, MENU_AUTOASSIGN, msg, desc );
6054 }
6055
6056 if( !is_valid_choice ) { // no body part can be chosen for this item/effect
6057 bmenu.init();
6058 bmenu.desc_enabled = false;
6059 bmenu.text = _( "No limb would benefit from it." );
6060 bmenu.addentry( parts.size(), true, 'q', "%s", _( "Cancel" ) );
6061 }
6062
6063 bmenu.query();
6064 if( bmenu.ret >= 0 && static_cast<size_t>( bmenu.ret ) < parts.size() &&
6065 parts[bmenu.ret].allowed ) {
6066 return parts[bmenu.ret].hp;
6067 } else {
6068 return num_hp_parts;
6069 }
6070}
int utf8_width(const char *s, const bool ignore_tags)
static const efftype_id effect_bleed("bleed")
static const efftype_id effect_infected("infected")
static const efftype_id effect_bite("bite")
static const std::string flag_SPLINT("SPLINT")
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3273
nc_color limb_color(const bodypart_id &bp, bool bleed, bool bite, bool infect) const
Definition: character.cpp:6072
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1327
virtual void bleed() const
Adds an appropriate blood splatter.
Definition: creature.cpp:131
int get_max_intensity() const
Returns the maximum intensity of an effect.
Definition: effect.cpp:853
time_duration get_duration() const
Returns the remaining duration of an effect.
Definition: effect.cpp:797
bool is_null() const
Returns true if the effect is the result of effect(), ie.
Definition: effect.cpp:553
int ret
Definition: ui.h:412
bool desc_enabled
Definition: ui.h:352
void addentry_desc(const std::string &str, const std::string &desc)
Definition: ui.cpp:942
bool hilight_disabled
Definition: ui.h:366
std::string text
Definition: ui.h:320
void addentry(const std::string &str)
Definition: ui.cpp:932
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_blue
Definition: color.h:23
#define c_yellow
Definition: color.h:32
#define c_red
Definition: color.h:21
std::string texitify_healing_power(const int power)
Definition: effect.cpp:1478
void query(bool loop=true, int timeout=-1)
Handle input and update display.
Definition: ui.cpp:828
void init()
Sane defaults on initialization.
Definition: ui.cpp:152
std::pair< std::string, nc_color > get_hp_bar(const int cur_hp, const int max_hp, const bool is_mon)
Definition: output.cpp:1604
hp_part
Definition: pldata.h:32
@ hp_torso
Definition: pldata.h:34
@ hp_leg_r
Definition: pldata.h:38
@ hp_arm_r
Definition: pldata.h:36
@ hp_head
Definition: pldata.h:33
@ hp_arm_l
Definition: pldata.h:35
@ num_hp_parts
Definition: pldata.h:39
@ hp_leg_l
Definition: pldata.h:37
const int MENU_AUTOASSIGN
Definition: ui.h:31

References _, uilist::addentry(), uilist::addentry_desc(), Creature::bleed(), c_blue, c_green, c_light_gray, c_light_green, c_red, c_white, c_yellow, colorize(), uilist::desc_enabled, effect_bandaged, effect_bite, effect_bleed, effect_disinfected, effect_infected, effect_mending, flag_SPLINT(), Creature::get_effect(), Creature::get_effect_int(), get_hp_bar(), effect::get_max_intensity(), Creature::get_part_hp_cur(), Creature::get_part_hp_max(), Creature::has_effect(), uilist::hilight_disabled, hp_arm_l, hp_arm_r, hp_head, hp_leg_l, hp_leg_r, hp_torso, uilist::init(), is_limb_broken(), limb_color(), MENU_AUTOASSIGN, name, num, num_hp_parts, uilist::query(), uilist::ret, string_format(), texitify_healing_power(), uilist::text, utf8_width(), and worn_with_flag().

Referenced by game::npc_menu(), and pick_part_to_heal().

◆ bodypart_exposure()

std::map< bodypart_id, float > Character::bodypart_exposure ( )

Map body parts to their total exposure, from 0.0 (fully covered) to 1.0 (buck naked).

Clothing layers are multiplied, ex. two layers of 50% coverage will leave only 25% exposed. Used to determine suffering effects of albinism and solar sensitivity.

Definition at line 779 of file suffer.cpp.

780{
781 std::map<bodypart_id, float> bp_exposure;
782 // May need to iterate over all body parts several times, so make a copy
783 const std::vector<bodypart_id> all_body_parts = get_all_body_parts();
784
785 // Initially, all parts are assumed to be fully exposed
786 for( const bodypart_id &bp : all_body_parts ) {
787 bp_exposure[bp] = 1.0;
788 }
789 // For every item worn, for every body part, adjust coverage
790 for( const item &it : worn ) {
791 // What body parts does this item cover?
792 body_part_set covered = it.get_covered_body_parts();
793 for( const bodypart_id &bp : all_body_parts ) {
794 if( bp->token != num_bp && !covered.test( bp->token ) ) {
795 continue;
796 }
797 // How much exposure does this item leave on this part? (1.0 == naked)
798 float part_exposure = 1.0 - it.get_coverage() / 100.0f;
799 // Coverage multiplies, so two layers with 50% coverage will together give 75%
800 bp_exposure[bp] = bp_exposure[bp] * part_exposure;
801 }
802 }
803 return bp_exposure;
804}
@ num_bp
Definition: bodypart.h:52
std::vector< bodypart_id > get_all_body_parts(bool only_main=false) const
Returns body parts this creature have.
Definition: creature.cpp:1627
bool test(const body_part &bp) const
Definition: bodypart.h:237

References all_body_parts, Creature::get_all_body_parts(), num_bp, body_part_set::test(), and worn.

Referenced by suffer_from_sunburn().

◆ bodytemp_color()

nc_color Character::bodytemp_color ( int  bp) const

Define color for displaying the body temperature.

Definition at line 10453 of file character.cpp.

10454{
10455 nc_color color = c_light_gray; // default
10456 if( bp == bp_eyes ) {
10457 color = c_light_gray; // Eyes don't count towards warmth
10458 } else if( temp_conv[bp] > BODYTEMP_SCORCHING ) {
10459 color = c_red;
10460 } else if( temp_conv[bp] > BODYTEMP_VERY_HOT ) {
10462 } else if( temp_conv[bp] > BODYTEMP_HOT ) {
10463 color = c_yellow;
10464 } else if( temp_conv[bp] > BODYTEMP_COLD ) {
10465 color = c_green;
10466 } else if( temp_conv[bp] > BODYTEMP_VERY_COLD ) {
10468 } else if( temp_conv[bp] > BODYTEMP_FREEZING ) {
10469 color = c_cyan;
10470 } else if( temp_conv[bp] <= BODYTEMP_FREEZING ) {
10471 color = c_blue;
10472 }
10473 return color;
10474}
#define c_light_blue
Definition: color.h:29
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
static nc_color color(const T_t &t)
static constexpr int BODYTEMP_SCORCHING
Definition: weather.h:42
static constexpr int BODYTEMP_VERY_HOT
Level 3 hotness.
Definition: weather.h:40
static constexpr int BODYTEMP_VERY_COLD
Frostbite timer will not improve while below this point.
Definition: weather.h:32
static constexpr int BODYTEMP_FREEZING
This value means frostbite occurs at the warmest temperature of 1C. If changed, the temp_conv calcula...
Definition: weather.h:30

References BODYTEMP_COLD, BODYTEMP_FREEZING, BODYTEMP_HOT, BODYTEMP_SCORCHING, BODYTEMP_VERY_COLD, BODYTEMP_VERY_HOT, bp_eyes, c_blue, c_cyan, c_green, c_light_blue, c_light_gray, c_light_red, c_red, c_yellow, color(), and temp_conv.

Referenced by character_display::print_encumbrance().

◆ bodytemp_modifier_traits()

int Character::bodytemp_modifier_traits ( bool  overheated) const

Correction factor of the body temperature due to traits and mutations.

Definition at line 9555 of file character.cpp.

9556{
9557 int mod = 0;
9558 for( const trait_id &iter : get_mutations() ) {
9559 mod += overheated ? iter->bodytemp_min : iter->bodytemp_max;
9560 }
9561 return mod;
9562}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References get_mutations().

Referenced by update_bodytemp().

◆ bodytemp_modifier_traits_floor()

int Character::bodytemp_modifier_traits_floor ( ) const

Correction factor of the body temperature due to traits and mutations for player lying on the floor.

Definition at line 9564 of file character.cpp.

9565{
9566 int mod = 0;
9567 for( const trait_id &iter : get_mutations() ) {
9568 mod += iter->bodytemp_sleep;
9569 }
9570 return mod;
9571}

References get_mutations().

Referenced by floor_warmth().

◆ bodyweight()

units::mass Character::bodyweight ( ) const

Definition at line 6878 of file character.cpp.

6879{
6880 return units::from_kilogram( bmi() * std::pow( height() / 100.0f, 2 ) );
6881}
int height() const
Definition: character.cpp:6959
float bmi() const
Definition: character.cpp:6873
constexpr quantity< value_type, mass_in_milligram_tag > from_kilogram(const value_type v)
Definition: units_mass.h:47

References bmi(), units::from_kilogram(), and height().

Referenced by get_weight(), and get_weight_string().

◆ bonus_damage()

float Character::bonus_damage ( bool  random) const

Returns the bonus bashing damage the player deals based on their stats.

Strength increases bashing damage

Definition at line 859 of file melee.cpp.

860{
861 /** @EFFECT_STR increases bashing damage */
862 if( random ) {
863 return rng_float( get_str() / 2.0f, get_str() );
864 }
865
866 return get_str() * 0.75f;
867}
virtual int get_str() const
Getters for stats exclusive to characters.
Definition: character.cpp:4080
type random()
Returns a random direction.
Definition: overmap.cpp:4209
double rng_float(double lo, double hi)
Definition: rng.cpp:28

References get_str(), om_direction::random(), and rng_float().

Referenced by draw_stats_info(), roll_bash_damage(), and set_stats().

◆ bonus_from_enchantments()

double Character::bonus_from_enchantments ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments for given base value.

Definition at line 8052 of file character.cpp.

8054{
8055 return enchantment_cache->calc_bonus( value, base, round );
8056}
pimpl< enchantment > enchantment_cache
Definition: character.h:2208

References enchantment_cache.

Referenced by armor_enchantment_adjust(), attack_cost(), known_magic::mana_regen_rate(), known_magic::max_mana(), metabolic_rate_base(), and run_cost().

◆ bp_to_hp()

hp_part Character::bp_to_hp ( body_part  bp)
static

Converts a body_part to an hp_part.

Definition at line 6578 of file character.cpp.

6579{
6580 switch( bp ) {
6581 case bp_head:
6582 case bp_eyes:
6583 case bp_mouth:
6584 return hp_head;
6585 case bp_torso:
6586 return hp_torso;
6587 case bp_arm_l:
6588 case bp_hand_l:
6589 return hp_arm_l;
6590 case bp_arm_r:
6591 case bp_hand_r:
6592 return hp_arm_r;
6593 case bp_leg_l:
6594 case bp_foot_l:
6595 return hp_leg_l;
6596 case bp_leg_r:
6597 case bp_foot_r:
6598 return hp_leg_r;
6599 default:
6600 return num_hp_parts;
6601 }
6602}

References bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, hp_arm_l, hp_arm_r, hp_head, hp_leg_l, hp_leg_r, hp_torso, and num_hp_parts.

Referenced by iexamine::autodoc(), explosion_handler::shrapnel(), and heal_actor::use_healing_item().

◆ build_mut_dependency_map()

void Character::build_mut_dependency_map ( const trait_id mut,
std::unordered_map< trait_id, int > &  dependency_map,
int  distance 
)

Recursively traverses the mutation's prerequisites and replacements, building up a map.

Definition at line 7915 of file character.cpp.

7917{
7918 // Skip base traits and traits we've seen with a lower distance
7919 const auto lowest_distance = dependency_map.find( mut );
7920 if( !has_base_trait( mut ) && ( lowest_distance == dependency_map.end() ||
7921 distance < lowest_distance->second ) ) {
7922 dependency_map[mut] = distance;
7923 // Recurse over all prerequisite and replacement mutations
7924 const mutation_branch &mdata = mut.obj();
7925 for( const trait_id &i : mdata.prereqs ) {
7926 build_mut_dependency_map( i, dependency_map, distance + 1 );
7927 }
7928 for( const trait_id &i : mdata.prereqs2 ) {
7929 build_mut_dependency_map( i, dependency_map, distance + 1 );
7930 }
7931 for( const trait_id &i : mdata.replacements ) {
7932 build_mut_dependency_map( i, dependency_map, distance + 1 );
7933 }
7934 }
7935}
void build_mut_dependency_map(const trait_id &mut, std::unordered_map< trait_id, int > &dependency_map, int distance)
Recursively traverses the mutation's prerequisites and replacements, building up a map.
Definition: character.cpp:7915
bool has_base_trait(const trait_id &b) const
Returns true if the player has the entered starting trait.
Definition: mutation.cpp:121
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:58
std::vector< trait_id > replacements
Definition: mutation.h:261
std::vector< trait_id > prereqs
Definition: mutation.h:256
std::vector< trait_id > prereqs2
Definition: mutation.h:257

References build_mut_dependency_map(), has_base_trait(), string_id< T >::obj(), mutation_branch::prereqs, mutation_branch::prereqs2, mutation_branch::replacements, and second.

Referenced by build_mut_dependency_map(), and set_highest_cat_level().

◆ burn_fuel()

bool Character::burn_fuel ( int  b,
bool  start = false 
)

Convert fuel to bionic power.

Definition at line 1156 of file bionics.cpp.

1157{
1158 bionic &bio = ( *my_bionics )[b];
1159 if( ( bio.info().fuel_opts.empty() && !bio.info().is_remote_fueled ) ||
1161 return true;
1162 }
1163 const bool is_metabolism_powered = bio.is_this_fuel_powered( fuel_type_metabolism );
1164 const bool is_cable_powered = bio.info().is_remote_fueled;
1165 std::vector<itype_id> fuel_available = get_fuel_available( bio.id );
1166 float effective_efficiency = get_effective_efficiency( b, bio.info().fuel_efficiency );
1167
1168 if( is_cable_powered ) {
1169 const itype_id remote_fuel = find_remote_fuel();
1170 if( !remote_fuel.is_empty() ) {
1171 fuel_available.emplace_back( remote_fuel );
1172 if( remote_fuel == fuel_type_sun_light ) {
1173 const item *pack = item_worn_with_flag( "SOLARPACK_ON" );
1174 effective_efficiency = pack != nullptr ? pack->type->solar_efficiency : 0;
1175 }
1176 // TODO: check for available fuel in remote source
1177 } else if( !start ) {
1179 _( "Your %s runs out of fuel and turn off." ),
1180 _( "<npcname>'s %s runs out of fuel and turn off." ),
1181 bio.info().name );
1182 bio.powered = false;
1183 deactivate_bionic( b, true );
1184 return false;
1185 }
1186 }
1187
1188 if( start && fuel_available.empty() ) {
1189 add_msg_player_or_npc( m_bad, _( "Your %s does not have enough fuel to start." ),
1190 _( "<npcname>'s %s does not have enough fuel to start." ),
1191 bio.info().name );
1193 return false;
1194 }
1195 // don't produce power on start to avoid instant recharge exploit by turning bionic ON/OFF
1196 //in the menu
1197 if( !start ) {
1198 for( const itype_id &fuel : fuel_available ) {
1199 const item &tmp_fuel = item( fuel );
1200 const int fuel_energy = tmp_fuel.fuel_energy();
1201 const bool is_perpetual_fuel = tmp_fuel.has_flag( flag_PERPETUAL );
1202
1203 int current_fuel_stock;
1204 if( is_metabolism_powered ) {
1205 current_fuel_stock = std::max( 0.0f, get_stored_kcal() - 0.8f *
1206 max_stored_kcal() );
1207 } else if( is_perpetual_fuel ) {
1208 current_fuel_stock = 1;
1209 } else if( is_cable_powered ) {
1210 current_fuel_stock = std::stoi( get_value( "rem_" + fuel.str() ) );
1211 } else {
1212 current_fuel_stock = std::stoi( get_value( fuel.str() ) );
1213 }
1214
1215 if( !bio.has_flag( flag_SAFE_FUEL_OFF ) &&
1216 get_power_level() + units::from_kilojoule( fuel_energy ) * effective_efficiency
1217 > get_max_power_level() ) {
1218 if( !bio.is_auto_start_keep_full() ) {
1219 if( is_metabolism_powered ) {
1220 add_msg_player_or_npc( m_info, _( "Your %s turns off to not waste calories." ),
1221 _( "<npcname>'s %s turns off to not waste calories." ),
1222 bio.info().name );
1223 } else if( is_perpetual_fuel ) {
1224 add_msg_player_or_npc( m_info, _( "Your %s turns off after filling your power banks." ),
1225 _( "<npcname>'s %s turns off after filling their power banks." ),
1226 bio.info().name );
1227 } else {
1228 add_msg_player_or_npc( m_info, _( "Your %s turns off to not waste fuel." ),
1229 _( "<npcname>'s %s turns off to not waste fuel." ),
1230 bio.info().name );
1231 }
1232 }
1233 bio.powered = false;
1234 deactivate_bionic( b, true );
1235 return false;
1236 } else {
1237 if( current_fuel_stock > 0 ) {
1238 map &here = get_map();
1239 if( is_metabolism_powered ) {
1240 const int kcal_consumed = fuel_energy;
1241 // 1kcal = 4187 J
1242 const units::energy power_gain = kcal_consumed * 4184_J * effective_efficiency;
1243 mod_stored_kcal( -kcal_consumed );
1244 mod_power_level( power_gain );
1245 } else if( is_perpetual_fuel ) {
1246 if( fuel == fuel_type_sun_light && g->is_in_sunlight( pos() ) ) {
1247 const weather_type_id &wtype = current_weather( pos() );
1248 const float tick_sunlight = incident_sunlight( wtype, calendar::turn );
1249 const double intensity = tick_sunlight / default_daylight_level();
1250 mod_power_level( units::from_kilojoule( fuel_energy ) * intensity * effective_efficiency );
1251 } else if( fuel == fuel_type_wind ) {
1252 int vehwindspeed = 0;
1253 const optional_vpart_position vp = here.veh_at( pos() );
1254 if( vp ) {
1255 // vehicle velocity in mph
1256 vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
1257 }
1258 const weather_manager &wm = get_weather();
1259 const double windpower = get_local_windpower( wm.windspeed + vehwindspeed,
1261 g->is_sheltered( pos() ) );
1262 mod_power_level( units::from_kilojoule( fuel_energy ) * windpower * effective_efficiency );
1263 }
1264 } else if( is_cable_powered ) {
1265 int to_consume = 1;
1267 to_consume = 0;
1268 }
1269 const int unconsumed = consume_remote_fuel( to_consume );
1270 if( unconsumed == 0 && to_consume == 1 ) {
1271 mod_power_level( units::from_kilojoule( fuel_energy ) * effective_efficiency );
1272 current_fuel_stock -= 1;
1273 } else if( to_consume == 1 ) {
1274 current_fuel_stock = 0;
1275 }
1276 set_value( "rem_" + fuel.str(), std::to_string( current_fuel_stock ) );
1277 } else {
1278 current_fuel_stock -= 1;
1279 set_value( fuel.str(), std::to_string( current_fuel_stock ) );
1280 update_fuel_storage( fuel );
1281 mod_power_level( units::from_kilojoule( fuel_energy ) * effective_efficiency );
1282 }
1283
1284 heat_emission( b, fuel_energy );
1285 if( bio.info().power_gen_emission ) {
1286 here.emit_field( pos(), bio.info().power_gen_emission );
1287 }
1288 } else {
1289
1290 if( is_metabolism_powered ) {
1292 _( "Stored calories are below the safe threshold, your %s shuts down to preserve your health." ),
1293 _( "Stored calories are below the safe threshold, <npcname>'s %s shuts down to preserve their health." ),
1294 bio.info().name );
1295 } else {
1296 remove_value( fuel.str() );
1298 _( "Your %s runs out of fuel and turn off." ),
1299 _( "<npcname>'s %s runs out of fuel and turn off." ),
1300 bio.info().name );
1301 }
1302
1303 bio.powered = false;
1304 deactivate_bionic( b, true );
1305 return false;
1306 }
1307 }
1308 }
1309 }
1310 return true;
1311}
static const std::string flag_SAFE_FUEL_OFF("SAFE_FUEL_OFF")
static const std::string flag_PERPETUAL("PERPETUAL")
static const itype_id fuel_type_wind("wind")
static const itype_id fuel_type_metabolism("metabolism")
static const itype_id fuel_type_muscle("muscle")
static const itype_id fuel_type_sun_light("sunlight")
double default_daylight_level()
How much light is provided in full daylight.
Definition: calendar.cpp:62
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
std::vector< itype_id > get_fuel_available(const bionic_id &bio) const
Return list of available fuel for this bionic.
Definition: character.cpp:2079
float get_effective_efficiency(int b, float fuel_efficiency)
Applies modifier to fuel_efficiency and returns the resulting efficiency.
Definition: bionics.cpp:1476
const item * item_worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns the first worn item with a given flag.
Definition: character.cpp:3281
virtual void mod_stored_kcal(int nkcal)
Modifiers for need values exclusive to characters.
Definition: character.cpp:4315
void heat_emission(int b, int fuel_energy)
Handle heat from exothermic power generation.
Definition: bionics.cpp:1455
int get_stored_kcal() const
Getter for need values exclusive to characters.
Definition: character.cpp:4310
int consume_remote_fuel(int amount)
Consume fuel used by remote powered bionic, return amount of request unfulfilled (0 if totally succes...
Definition: bionics.cpp:1412
void update_fuel_storage(const itype_id &fuel)
Updates which bionic contain fuel and which is empty.
Definition: character.cpp:2125
itype_id find_remote_fuel(bool look_only=false)
Find fuel used by remote powered bionic.
Definition: bionics.cpp:1358
void set_value(const std::string &key, const std::string &value)
Definition: creature.cpp:1331
float fuel_energy() const
Returns energy of one charge of this item as fuel for an engine.
Definition: item.cpp:6660
const itype * type
Definition: item.h:2156
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1928
int winddirection
Definition: weather.h:194
const weather_type_id & current_weather(const tripoint &location, const time_point &t)
Definition: weather.cpp:143
int incident_sunlight(const weather_type_id &wtype, const time_point &t)
Amount of sunlight incident at the ground, taking weather and time of day into account.
Definition: weather.cpp:107
emit_id power_gen_emission
Type of field emitted by this bionic when it produces energy.
Definition: bionics.h:75
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:63
float fuel_efficiency
Fraction of fuel energy converted to bionic power.
Definition: bionics.h:67
bool has_flag(const std::string &flag) const
Definition: bionics.cpp:2681
bool is_this_fuel_powered(const itype_id &this_fuel) const
Definition: bionics.cpp:2696
float solar_efficiency
Efficiency of solar energy conversion for solarpacks.
Definition: itype.h:1040

References _, Creature::add_msg_player_or_npc(), b, consume_remote_fuel(), current_weather(), deactivate_bionic(), default_daylight_level(), map::emit_field(), find_remote_fuel(), flag_PERPETUAL(), flag_SAFE_FUEL_OFF(), units::from_kilojoule(), bionic_data::fuel_efficiency, item::fuel_energy(), bionic_data::fuel_opts, fuel_type_metabolism, fuel_type_muscle, fuel_type_sun_light, fuel_type_wind, g, get_effective_efficiency(), get_fuel_available(), get_local_windpower(), get_map(), get_max_power_level(), get_power_level(), get_stored_kcal(), Creature::get_value(), get_weather(), global_omt_location(), bionic::has_flag(), item::has_flag(), heat_emission(), bionic::id, incident_sunlight(), bionic::info(), bionic::is_auto_start_keep_full(), string_id< T >::is_empty(), bionic_data::is_remote_fueled, bionic::is_this_fuel_powered(), item_worn_with_flag(), m_bad, m_info, max_stored_kcal(), mod_power_level(), mod_stored_kcal(), bionic_data::name, overmap_buffer, pos(), bionic_data::power_gen_emission, bionic::powered, Creature::remove_value(), Creature::set_value(), itype::solar_efficiency, overmapbuffer::ter(), to_string(), calendar::turn, item::type, update_fuel_storage(), map::veh_at(), weather_manager::winddirection, and weather_manager::windspeed.

Referenced by activate_bionic(), and process_bionic().

◆ burn_move_stamina()

void Character::burn_move_stamina ( int  moves)

Definition at line 7237 of file character.cpp.

7238{
7239 int overburden_percentage = 0;
7240 units::mass current_weight = weight_carried();
7241 // Make it at least 1 gram to avoid divide-by-zero warning
7242 units::mass max_weight = std::max( weight_capacity(), 1_gram );
7243 if( current_weight > max_weight ) {
7244 overburden_percentage = ( current_weight - max_weight ) * 100 / max_weight;
7245 }
7246
7247 int burn_ratio = get_option<int>( "PLAYER_BASE_STAMINA_BURN_RATE" );
7248 for( const bionic_id &bid : get_bionic_fueled_with( item( "muscle" ) ) ) {
7249 if( has_active_bionic( bid ) ) {
7250 burn_ratio = burn_ratio * 2 - 3;
7251 }
7252 }
7253 burn_ratio += overburden_percentage;
7254 if( move_mode == CMM_RUN ) {
7255 burn_ratio = burn_ratio * 7;
7256 }
7257 mod_stamina( -( ( moves * burn_ratio ) / 100.0 ) * stamina_move_cost_modifier() );
7258 add_msg( m_debug, "Stamina burn: %d", -( ( moves * burn_ratio ) / 100 ) );
7259 // Chance to suffer pain if overburden and stamina runs out or has trait BADBACK
7260 // Starts at 1 in 25, goes down by 5 for every 50% more carried
7261 if( ( current_weight > max_weight ) && ( has_trait( trait_BADBACK ) || get_stamina() == 0 ) &&
7262 one_in( 35 - 5 * current_weight / ( max_weight / 2 ) ) ) {
7263 add_msg_if_player( m_bad, _( "Your body strains under the weight!" ) );
7264 // 1 more pain for every 800 grams more (5 per extra STR needed)
7265 if( ( ( current_weight - max_weight ) / 800_gram > get_pain() && get_pain() < 100 ) ) {
7266 mod_pain( 1 );
7267 }
7268 }
7269}
static const trait_id trait_BADBACK("BADBACK")
@ CMM_RUN
Definition: character.h:102
std::vector< bionic_id > get_bionic_fueled_with(const item &it) const
Return bionic_id of bionics able to use it as fuel.
Definition: character.cpp:1931
units::mass weight_carried() const
Definition: character.cpp:2722
void mod_stamina(int mod)
Definition: character.cpp:7227
float stamina_move_cost_modifier() const
Definition: character.cpp:7271
virtual int get_pain() const
Definition: creature.cpp:1366

References _, add_msg(), Creature::add_msg_if_player(), CMM_RUN, get_bionic_fueled_with(), Creature::get_pain(), get_stamina(), has_active_bionic(), has_trait(), m_bad, m_debug, Creature::mod_pain(), mod_stamina(), move_mode, Creature::moves, one_in(), stamina_move_cost_modifier(), trait_BADBACK, weight_capacity(), and weight_carried().

Referenced by avatar_action::swim(), and game::walk_move().

◆ calc_all_parts_hp()

void Character::calc_all_parts_hp ( float  hp_mod = 0.0,
float  hp_adjust = 0.0,
int  str_max = 0 
)

Sets hp for all body parts.

Definition at line 1676 of file character.cpp.

1677{
1678 for( const std::pair<const bodypart_str_id, bodypart> &part : get_body() ) {
1679 bodypart &bp = *get_part( part.first );
1680 int new_max = ( part.first->base_hp + str_max * 3 + hp_adjustment ) * hp_mod;
1681
1682 if( has_trait( trait_id( "GLASSJAW" ) ) && part.first == bodypart_str_id( "head" ) ) {
1683 new_max *= 0.8;
1684 }
1685
1686 float max_hp_ratio = static_cast<float>( new_max ) /
1687 static_cast<float>( bp.get_hp_max() );
1688
1689 int new_cur = std::ceil( static_cast<float>( bp.get_hp_cur() ) * max_hp_ratio );
1690
1691 bp.set_hp_max( std::max( new_max, 1 ) );
1692 bp.set_hp_cur( std::max( std::min( new_cur, new_max ), 0 ) );
1693 }
1694}
string_id< body_part_type > bodypart_str_id
Definition: bodypart.h:22
const std::map< bodypart_str_id, bodypart > & get_body() const
Definition: creature.cpp:1527
bodypart * get_part(const bodypart_id &id)
Definition: creature.cpp:1540
int get_hp_max() const
Definition: bodypart.cpp:400
int get_hp_cur() const
Definition: bodypart.cpp:395
void set_hp_max(int set)
Definition: bodypart.cpp:425
void set_hp_cur(int set)
Definition: bodypart.cpp:420

References Creature::get_body(), bodypart::get_hp_cur(), bodypart::get_hp_max(), Creature::get_part(), has_trait(), bodypart::set_hp_cur(), bodypart::set_hp_max(), str_max, and trait_id.

Referenced by recalc_hp().

◆ calc_encumbrance() [1/2]

char_encumbrance_data Character::calc_encumbrance ( ) const
protected

Recalculate encumbrance for all body parts.

Definition at line 3651 of file character.cpp.

3652{
3653 return calc_encumbrance( item() );
3654}
char_encumbrance_data calc_encumbrance() const
Recalculate encumbrance for all body parts.
Definition: character.cpp:3651

References calc_encumbrance().

Referenced by calc_encumbrance(), get_encumbrance(), on_item_takeoff(), on_item_wear(), and reset_encumbrance().

◆ calc_encumbrance() [2/2]

char_encumbrance_data Character::calc_encumbrance ( const item new_item) const
protected

Recalculate encumbrance for all body parts as if new_item was also worn.

Definition at line 3656 of file character.cpp.

3657{
3658
3660
3661 item_encumb( enc, new_item );
3662 mut_cbm_encumb( enc );
3663
3664 return enc;
3665}
void item_encumb(char_encumbrance_data &vals, const item &new_item) const
Applies encumbrance from items only If new_item is not null, then calculate under the asumption that ...
Definition: character.cpp:3974
void mut_cbm_encumb(char_encumbrance_data &vals) const
Applies encumbrance from mutations and bionics only.
Definition: character.cpp:4037

References item_encumb(), and mut_cbm_encumb().

◆ calc_needs_rates()

needs_rates Character::calc_needs_rates ( ) const

Definition at line 4908 of file character.cpp.

4909{
4910 const effect &sleep = get_effect( effect_sleep );
4911 const bool has_recycler = has_bionic( bio_recycler );
4912 const bool asleep = !sleep.is_null();
4913
4914 needs_rates rates;
4915 rates.hunger = metabolic_rate();
4916
4917 add_msg_if_player( m_debug, "Metabolic rate: %.2f", rates.hunger );
4918
4919 static const std::string player_thirst_rate( "PLAYER_THIRST_RATE" );
4920 rates.thirst = get_option< float >( player_thirst_rate );
4921 static const std::string thirst_modifier( "thirst_modifier" );
4922 rates.thirst *= 1.0f + mutation_value( thirst_modifier );
4923 static const std::string slows_thirst( "SLOWS_THIRST" );
4924 if( worn_with_flag( slows_thirst ) ) {
4925 rates.thirst *= 0.7f;
4926 }
4927
4928 static const std::string player_fatigue_rate( "PLAYER_FATIGUE_RATE" );
4929 rates.fatigue = get_option< float >( player_fatigue_rate );
4930 static const std::string fatigue_modifier( "fatigue_modifier" );
4931 rates.fatigue *= 1.0f + mutation_value( fatigue_modifier );
4932
4933 // Note: intentionally not in metabolic rate
4934 if( has_recycler ) {
4935 // Recycler won't help much with mutant metabolism - it is intended for human one
4936 rates.hunger = std::min( rates.hunger, std::max( 0.5f, rates.hunger - 0.5f ) );
4937 rates.thirst = std::min( rates.thirst, std::max( 0.5f, rates.thirst - 0.5f ) );
4938 }
4939
4940 if( asleep ) {
4941 static const std::string fatigue_regen_modifier( "fatigue_regen_modifier" );
4942 // Multiplied by 2 to account for legacy (bugged to always apply)
4943 // bonus for sleeping over 2 hours
4944 rates.recovery = 2.0f * ( 1.0f + mutation_value( fatigue_regen_modifier ) );
4945 if( is_hibernating() ) {
4946 // Hunger and thirst advance *much* more slowly whilst we hibernate.
4947 rates.hunger *= ( 1.0f / 7.0f );
4948 rates.thirst *= ( 1.0f / 7.0f );
4949 }
4950 rates.recovery -= static_cast<float>( get_perceived_pain() ) / 60;
4951
4952 } else {
4953 rates.recovery = 0;
4954 }
4955
4957 // Much of the body's needs are taken care of by the trees.
4958 // Hair Roots don't provide any bodily needs.
4960 rates.hunger *= 0.5f;
4961 rates.thirst *= 0.5f;
4962 rates.fatigue *= 0.5f;
4963 }
4964 }
4965
4967 // Transpiration, the act of moving nutrients with evaporating water, can take a very heavy toll on your thirst when it's really hot.
4968 rates.thirst *= ( ( get_weather().get_temperature( pos() ) - 32.5f ) / 40.0f );
4969 }
4970
4971 if( is_npc() ) {
4972 rates.hunger *= 0.25f;
4973 rates.thirst *= 0.25f;
4974 }
4975
4976 return rates;
4977}
static const activity_id ACT_TREE_COMMUNION("ACT_TREE_COMMUNION")
static const trait_id trait_ROOTS2("ROOTS2")
static const bionic_id bio_recycler("bio_recycler")
static const efftype_id effect_sleep("sleep")
static const trait_id trait_TRANSPIRATION("TRANSPIRATION")
static const trait_id trait_ROOTS3("ROOTS3")
float metabolic_rate() const
Current metabolic rate due to traits, hunger, speed, etc.
bool is_hibernating() const
Returns if the player has hibernation mutation and is asleep and well fed.
Definition: character.cpp:5158
bool has_activity(const activity_id &type) const
Check if player currently has a given activity.
Definition: character.cpp:9236
virtual int get_perceived_pain() const
Definition: creature.cpp:1371
int get_temperature(const tripoint &location) const
Definition: weather.cpp:1107
static void sleep()
float hunger
Definition: player.h:84
float recovery
Definition: player.h:86
float fatigue
Definition: player.h:85
float thirst
Definition: player.h:83

References ACT_TREE_COMMUNION, Creature::add_msg_if_player(), bio_recycler, effect_sleep, needs_rates::fatigue, Creature::get_effect(), Creature::get_perceived_pain(), weather_manager::get_temperature(), get_weather(), has_activity(), has_bionic(), has_trait(), needs_rates::hunger, is_hibernating(), Creature::is_npc(), m_debug, metabolic_rate(), mutation_value(), pos(), needs_rates::recovery, sleep(), needs_rates::thirst, trait_ROOTS2, trait_ROOTS3, trait_TRANSPIRATION, and worn_with_flag().

Referenced by update_needs(), and update_stomach().

◆ can_consume()

bool Character::can_consume ( const item it) const

Check character's capability of consumption overall.

Definition at line 1512 of file consumption.cpp.

1513{
1514 if( can_consume_as_is( it ) ) {
1515 return true;
1516 }
1517 // Checking NO_RELOAD to prevent consumption of `battery` when contained in `battery_car` (#20012)
1518 return !it.is_container_empty() && !it.has_flag( flag_NO_RELOAD ) &&
1520}
bool can_consume_as_is(const item &it) const
Check whether character can consume this very item.
item & front()
this is an artifact of the previous code using front() everywhere for contents.
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6681
static const std::string flag_NO_RELOAD("NO_RELOAD")

References can_consume_as_is(), item::contents, flag_NO_RELOAD(), item_contents::front(), item::has_flag(), and item::is_container_empty().

Referenced by find_auto_consume(), and rate_action_eat().

◆ can_consume_as_is()

bool Character::can_consume_as_is ( const item it) const

Check whether character can consume this very item.

Definition at line 1502 of file consumption.cpp.

1503{
1504 return it.is_comestible() || can_consume_for_bionic( it );
1505}
bool can_consume_for_bionic(const item &it) const
bool is_comestible() const
Definition: item.cpp:6431

References can_consume_for_bionic(), and item::is_comestible().

Referenced by can_consume(), player::consume(), avatar_action::eat(), and get_consumable_from().

◆ can_consume_for_bionic()

bool Character::can_consume_for_bionic ( const item it) const

Definition at line 1507 of file consumption.cpp.

1508{
1510}
rechargeable_cbm get_cbm_rechargeable_with(const item &it) const

References get_cbm_rechargeable_with(), and none.

Referenced by can_consume_as_is().

◆ can_eat()

ret_val< edible_rating > Character::can_eat ( const item food) const

Can the food be [theoretically] eaten no matter the consequen ces?

Definition at line 638 of file consumption.cpp.

639{
640
641 const auto &comest = food.get_comestible();
642 if( !comest ) {
643 return ret_val<edible_rating>::make_failure( _( "That doesn't look edible." ) );
644 }
645
646 if( food.has_flag( flag_INEDIBLE ) ) {
647 if( ( food.has_flag( flag_CATTLE ) && !has_trait( trait_THRESH_CATTLE ) ) ||
650 ( food.has_flag( flag_BIRD ) && !has_trait( trait_THRESH_BIRD ) ) ) {
651 return ret_val<edible_rating>::make_failure( _( "That doesn't look edible to you." ) );
652 }
653 }
654
655 if( food.is_craft() ) {
656 return ret_val<edible_rating>::make_failure( _( "That doesn't look edible in its current form." ) );
657 }
658
659 if( food.has_own_flag( "DIRTY" ) ) {
661 _( "This is full of dirt after being on the ground." ) );
662 }
663
664 const bool eat_verb = food.has_flag( flag_USE_EAT_VERB );
665 const bool edible = eat_verb || comest->comesttype == comesttype_FOOD;
666 const bool drinkable = !eat_verb && comest->comesttype == comesttype_DRINK;
667
668 // TODO: This condition occurs way too often. Unify it.
669 // update Sep. 26 2018: this apparently still occurs way too often. yay!
671 return ret_val<edible_rating>::make_failure( _( "You can't do that while underwater." ) );
672 }
673
674 if( edible || drinkable ) {
675 for( const auto &elem : food.type->materials ) {
676 if( !elem->edible() ) {
677 return ret_val<edible_rating>::make_failure( _( "That doesn't look edible in its current form." ) );
678 }
679 }
680 }
681
682 if( !comest->tool.is_null() ) {
683 const bool has = item::count_by_charges( comest->tool )
684 ? has_charges( comest->tool, 1 )
685 : has_amount( comest->tool, 1 );
686 if( !has ) {
688 string_format( _( "You need a %s to consume that!" ),
689 item::nname( comest->tool ) ) );
690 }
691 }
692
693 // For all those folks who loved eating marloss berries. D:< mwuhahaha
695 !food.has_flag( flag_NO_INGEST ) ) {
697 _( "We can't eat that. It's not right for us." ) );
698 }
699 // Here's why PROBOSCIS is such a negative trait.
700 if( has_trait( trait_PROBOSCIS ) && !( drinkable || food.is_medication() ) ) {
702 _( "Ugh, you can't drink that!" ) );
703 }
704
705 if( has_trait( trait_CARNIVORE ) && nutrition_for( food ) > 0 &&
708 _( "Eww. Inedible plant stuff!" ) );
709 }
710
713 // Like non-cannibal, but more strict!
715 _( "The thought of eating that makes you feel sick." ) );
716 }
717
718 for( const trait_id &mut : get_mutations() ) {
719 if( !food.made_of_any( mut.obj().can_only_eat ) && !mut.obj().can_only_eat.empty() &&
720 !food.has_flag( flag_NO_INGEST ) ) {
722 _( "You can't eat this." ) );
723 }
724 }
725
727}
bool has_charges(const itype_id &it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >) const
Definition: character.cpp:9612
int nutrition_for(const item &comest) const
Handles the nutrition value for a comestible.
virtual bool is_underwater() const
Definition: creature.cpp:174
bool count_by_charges() const
Definition: item.cpp:5849
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:9945
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9743
bool is_craft() const
Definition: item.cpp:6762
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6279
bool is_medication() const
Definition: item.cpp:6442
bool has_any_flag(const Container &flags) const
Definition: item.h:1402
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5181
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
bool has_amount(const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
Check instance provides at least qty of an item (.
Definition: visitable.cpp:1108
static const trait_id trait_RUMINANT("RUMINANT")
const std::vector< std::string > carnivore_blacklist
static const std::string flag_INEDIBLE("INEDIBLE")
static const trait_id trait_HERBIVORE("HERBIVORE")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string comesttype_DRINK("DRINK")
static const trait_id trait_THRESH_BIRD("THRESH_BIRD")
const std::vector< std::string > herbivore_blacklist(temparray.begin(), temparray.end())
static const std::string flag_BIRD("BIRD")
static const trait_id trait_PROBOSCIS("PROBOSCIS")
static const std::string flag_USE_EAT_VERB("USE_EAT_VERB")
static const std::string flag_MYCUS_OK("MYCUS_OK")
static const std::string flag_CATTLE("CATTLE")
static const trait_id trait_THRESH_LUPINE("THRESH_LUPINE")
static const trait_id trait_THRESH_CATTLE("THRESH_CATTLE")
static const trait_id trait_THRESH_FELINE("THRESH_FELINE")
static const std::string comesttype_FOOD("FOOD")
static const std::string flag_CARNIVORE_OK("CARNIVORE_OK")
static const trait_id trait_WATERSLEEP("WATERSLEEP")
static const std::string flag_FELINE("FELINE")
static const trait_id trait_M_DEPENDENT("M_DEPENDENT")
static const std::string flag_NO_INGEST("NO_INGEST")
static const std::string flag_LUPINE("LUPINE")
std::vector< material_id > materials
Definition: itype.h:922

References _, carnivore_blacklist, comesttype_DRINK(), comesttype_FOOD(), item::count_by_charges(), edible, flag_BIRD(), flag_CARNIVORE_OK(), flag_CATTLE(), flag_FELINE(), flag_INEDIBLE(), flag_LUPINE(), flag_MYCUS_OK(), flag_NO_INGEST(), flag_USE_EAT_VERB(), item::get_comestible(), get_mutations(), visitable< Character >::has_amount(), item::has_any_flag(), has_charges(), item::has_flag(), item::has_own_flag(), has_trait(), herbivore_blacklist(), inedible_mutation, item::is_craft(), item::is_medication(), item::is_null(), Creature::is_underwater(), item::made_of_any(), ret_val< T >::make_failure(), ret_val< T >::make_success(), itype::materials, item::nname(), no_tool, nutrition_for(), string_format(), trait_CARNIVORE, trait_HERBIVORE, trait_M_DEPENDENT, trait_PROBOSCIS, trait_RUMINANT, trait_THRESH_BIRD, trait_THRESH_CATTLE, trait_THRESH_FELINE, trait_THRESH_LUPINE, trait_WATERSLEEP, and item::type.

Referenced by can_feed_furnace_with(), can_feed_reactor_with(), player::eat(), and will_eat().

◆ can_estimate_rot()

bool Character::can_estimate_rot ( ) const

True if the character has enough skill (in cooking or survival) to estimate time to rot.

Definition at line 1497 of file consumption.cpp.

1498{
1500}
static const skill_id skill_survival("survival")
static const skill_id skill_cooking("cooking")

References get_skill_level(), skill_cooking, and skill_survival.

◆ can_feed_furnace_with()

bool Character::can_feed_furnace_with ( const item it) const

Definition at line 1321 of file consumption.cpp.

1322{
1323 if( !it.flammable() || it.has_flag( flag_RADIOACTIVE ) || can_eat( it ).success() ) {
1324 return false;
1325 }
1326
1327 if( !has_active_bionic( bio_furnace ) ) {
1328 return false;
1329 }
1330
1331 // Not even one charge fits
1332 if( it.charges_per_volume( furnace_max_volume ) < 1 ) {
1333 return false;
1334 }
1335
1336 return !it.has_flag( flag_CORPSE );
1337}
ret_val< edible_rating > can_eat(const item &food) const
Can the food be [theoretically] eaten no matter the consequen ces?
bool flammable(int threshold=0) const
Whether the items is flammable.
Definition: item.cpp:8153
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:863
const units::volume furnace_max_volume(3_liter)
static const bionic_id bio_furnace("bio_furnace")
static const std::string flag_CORPSE("CORPSE")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")

References bio_furnace, can_eat(), item::charges_per_volume(), flag_CORPSE(), flag_RADIOACTIVE(), item::flammable(), furnace_max_volume, has_active_bionic(), item::has_flag(), and behavior::success.

Referenced by feed_furnace_with(), and get_cbm_rechargeable_with().

◆ can_feed_reactor_with()

bool Character::can_feed_reactor_with ( const item it) const

Determine character's capability of recharging their CBMs.

Definition at line 1274 of file consumption.cpp.

1275{
1276 static const std::set<ammotype> acceptable = {{
1277 ammotype( "reactor_slurry" ),
1278 ammotype( "plutonium" )
1279 }
1280 };
1281
1282 if( !it.is_ammo() || can_eat( it ).success() ) {
1283 return false;
1284 }
1285
1287 return false;
1288 }
1289
1290 return std::any_of( acceptable.begin(), acceptable.end(), [ &it ]( const ammotype & elem ) {
1291 return it.ammo_type() == elem;
1292 } );
1293}
bool is_ammo() const
Definition: item.cpp:6426
static const bionic_id bio_reactor("bio_reactor")
static const bionic_id bio_advreactor("bio_advreactor")
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References bio_advreactor, bio_reactor, can_eat(), has_active_bionic(), item::is_ammo(), and behavior::success.

Referenced by feed_reactor_with(), and get_cbm_rechargeable_with().

◆ can_fuel_bionic_with()

bool Character::can_fuel_bionic_with ( const item it) const

Returns true if the character can fuel a bionic with the item.

Definition at line 1915 of file character.cpp.

1916{
1917 if( !it.is_fuel() ) {
1918 return false;
1919 }
1920
1921 for( const bionic_id &bid : get_bionics() ) {
1922 for( const itype_id &fuel : bid->fuel_opts ) {
1923 if( fuel == it.typeId() ) {
1924 return true;
1925 }
1926 }
1927 }
1928 return false;
1929}
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8190
bool is_fuel() const
Definition: item.cpp:6604

References get_bionics(), item::is_fuel(), and item::typeId().

Referenced by fuel_bionic_with(), and get_cbm_rechargeable_with().

◆ can_hear()

bool Character::can_hear ( const tripoint source,
int  volume 
) const

Definition at line 10272 of file character.cpp.

10273{
10274 if( is_deaf() ) {
10275 return false;
10276 }
10277
10278 // source is in-ear and at our square, we can hear it
10279 if( source == pos() && volume == 0 ) {
10280 return true;
10281 }
10282 const int dist = rl_dist( source, pos() );
10283 const float volume_multiplier = hearing_ability();
10284 return ( volume - get_weather().weather_id->sound_attn ) * volume_multiplier >= dist;
10285}
float hearing_ability() const
bool is_deaf() const
Definition: character.cpp:4502
quantity< int, volume_in_milliliter_tag > volume
Definition: units_volume.h:16

References get_weather(), hearing_ability(), is_deaf(), pos(), and rl_dist().

Referenced by game::chat(), iuse::geiger(), iuse::play_music(), iuse::talking_doll(), and musical_instrument_actor::use().

◆ can_install_bionics()

bool Character::can_install_bionics ( const itype type,
player installer,
bool  autodoc = false,
int  skill_level = -1 
)

Is the installation possible.

Definition at line 2158 of file bionics.cpp.

2160{
2161 if( !type.bionic ) {
2162 debugmsg( "Tried to install NULL bionic" );
2163 return false;
2164 }
2165 if( is_mounted() ) {
2166 return false;
2167 }
2168
2169 const bionic_id &bioid = type.bionic->id;
2170 const int difficult = type.bionic->difficulty;
2171 float adjusted_skill;
2172
2173 if( autodoc ) {
2174 adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
2177 skill_level );
2178 } else {
2179 adjusted_skill = installer.bionics_adjusted_skill( skill_electronics,
2182 skill_level );
2183 }
2184 int chance_of_success = bionic_manip_cos( adjusted_skill, difficult );
2185
2186 std::vector<std::string> conflicting_muts;
2187 for( const trait_id &mid : bioid->canceled_mutations ) {
2188 if( has_trait( mid ) ) {
2189 conflicting_muts.push_back( mid->name() );
2190 }
2191 }
2192
2193 if( !conflicting_muts.empty() &&
2194 !query_yn(
2195 _( "Installing this bionic will remove the conflicting traits: %s. Continue anyway?" ),
2196 enumerate_as_string( conflicting_muts ) ) ) {
2197 return false;
2198 }
2199
2200 const std::map<bodypart_id, int> &issues = bionic_installation_issues( bioid );
2201 // show all requirements which are not satisfied
2202 if( !issues.empty() ) {
2203 std::string detailed_info;
2204 for( auto &elem : issues ) {
2205 //~ <Body part name>: <number of slots> more slot(s) needed.
2206 detailed_info += string_format( _( "\n%s: %i more slot(s) needed." ),
2207 body_part_name_as_heading( elem.first->token, 1 ),
2208 elem.second );
2209 }
2210 popup( _( "Not enough space for bionic installation!%s" ), detailed_info );
2211 return false;
2212 }
2213
2214 if( chance_of_success >= 100 ) {
2215 if( !g->u.query_yn(
2216 _( "Are you sure you wish to install the selected bionic?" ),
2217 100 - chance_of_success ) ) {
2218 return false;
2219 }
2220 } else {
2221 if( autodoc ) {
2222 if( !g->u.query_yn(
2223 _( "WARNING: There is a %i percent chance of complications, such as damage or faulty installation! Continue anyway?" ),
2224 ( 100 - chance_of_success ) ) ) {
2225 return false;
2226 }
2227 } else {
2228 if( !g->u.query_yn(
2229 _( "WARNING: There is a %i percent chance of complications, such as damage or faulty installation! The following skills affect self-installation: First Aid, Electronics, and Mechanics.\n\nContinue anyway?" ),
2230 ( 100 - chance_of_success ) ) ) {
2231 return false;
2232 }
2233 }
2234 }
2235
2236 return true;
2237}
int bionic_manip_cos(float adjusted_skill, int bionic_difficulty)
Definition: bionics.cpp:1889
static const skill_id skill_mechanics("mechanics")
static const skill_id skill_computer("computer")
static const skill_id skill_firstaid("firstaid")
static const skill_id skill_electronics("electronics")
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:341
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2507
float bionics_adjusted_skill(const skill_id &most_important_skill, const skill_id &important_skill, const skill_id &least_important_skill, int skill_level=-1)
Calculate skill for (un)installing bionics.
Definition: bionics.cpp:1846
void autodoc(player &p, const tripoint &examp)
Definition: iexamine.cpp:4719
int popup(const std::string &text, PopupFlags flags)
Definition: output.cpp:764
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:679
std::vector< trait_id > canceled_mutations
Mutations/trait that are removed upon installing this CBM.
Definition: bionics.h:104
std::string name() const

References _, iexamine::autodoc(), bionic_installation_issues(), bionic_manip_cos(), bionics_adjusted_skill(), body_part_name_as_heading(), bionic_data::canceled_mutations, debugmsg, enumerate_as_string(), g, has_trait(), is_mounted(), mutation_branch::name(), popup(), query_yn(), skill_computer, skill_electronics, skill_firstaid, skill_mechanics, string_format(), and type.

Referenced by iexamine::autodoc(), and install_bionic_actor::use().

◆ can_install_cbm_on_bp()

bool Character::can_install_cbm_on_bp ( const std::vector< bodypart_id > &  bps) const

Definition at line 456 of file mutation.cpp.

457{
458 bool can_install = true;
459 for( const trait_id &mut : get_mutations() ) {
460 for( const bodypart_id &bp : bps ) {
461 if( mut.obj().no_cbm_on_bp.count( bp.id() ) ) {
462 can_install = false;
463 break;
464 }
465 }
466 }
467 return can_install;
468}

References get_mutations().

Referenced by bionic_install_preset::get_denial().

◆ can_miss_recovery()

bool Character::can_miss_recovery ( const item weap) const

Returns true if the player is able to use a miss recovery technique.

Definition at line 948 of file martialarts.cpp.

949{
950 if( !martial_arts_data->has_miss_recovery_tec( weap ) ) {
951 return false;
952 }
953
954 ma_technique tec = martial_arts_data->get_miss_recovery_tec( weap );
955
956 return tec.is_valid_character( *this );
957}
bool is_valid_character(const Character &u) const

References ma_technique::is_valid_character(), and martial_arts_data.

Referenced by melee_attack().

◆ can_mount()

bool Character::can_mount ( const monster critter) const

Definition at line 508 of file monexamine.cpp.

509{
510 const auto &avoid = get_path_avoid();
511 auto route = g->m.route( pos(), critter.pos(), get_pathfinding_settings(), avoid );
512
513 if( route.empty() ) {
514 return false;
515 }
516 return ( critter.has_flag( MF_PET_MOUNTABLE ) && critter.friendly == -1 &&
517 !critter.has_effect( effect_ai_waiting ) && !critter.has_effect( effect_ridden ) ) &&
518 ( ( critter.has_effect( effect_saddled ) && get_skill_level( skill_survival ) >= 1 ) ||
519 get_skill_level( skill_survival ) >= 4 ) && ( critter.get_size() >= ( get_size() + 1 ) &&
520 get_weight() <= critter.get_weight() * critter.get_mountable_weight_ratio() );
521}
units::mass get_weight() const override
Returns body weight plus weight of inventory and worn/wielded items.
Definition: character.cpp:3667
std::set< tripoint > get_path_avoid() const override
Returns a set of points we do not want to path through.
Definition: character.cpp:9960
m_size get_size() const override
Get size class of character.
Definition: character.cpp:541
const pathfinding_settings & get_pathfinding_settings() const override
Returns settings for pathfinding.
Definition: character.cpp:9974
bool has_flag(m_flag f) const override
Definition: monster.cpp:869
m_size get_size() const override
Definition: monster.cpp:2672
const tripoint & pos() const override
Definition: monster.cpp:255
units::mass get_weight() const override
Definition: monster.cpp:2677
float get_mountable_weight_ratio() const
Definition: monster.cpp:2908
static const efftype_id effect_ai_waiting("ai_waiting")
static const efftype_id effect_ridden("ridden")
static const efftype_id effect_saddled("monster_saddled")
static const skill_id skill_survival("survival")
@ MF_PET_MOUNTABLE
Definition: mtype.h:164

References effect_ai_waiting, effect_ridden, effect_saddled, monster::friendly, g, monster::get_mountable_weight_ratio(), get_path_avoid(), get_pathfinding_settings(), get_size(), monster::get_size(), get_skill_level(), get_weight(), monster::get_weight(), Creature::has_effect(), monster::has_flag(), MF_PET_MOUNTABLE, pos(), monster::pos(), and skill_survival.

Referenced by talk_function::find_mount(), and activity_handlers::find_mount_do_turn().

◆ can_pick_volume() [1/2]

bool Character::can_pick_volume ( const item it) const

Definition at line 2890 of file character.cpp.

2891{
2892 inventory projected = inv;
2893 projected.add_item( it, true );
2894 return projected.volume() <= volume_capacity();
2895}
item & add_item(item newit, bool keep_invlet=false, bool assign_invlet=true, bool should_stack=true)
Definition: inventory.cpp:285
units::volume volume() const
Definition: inventory.cpp:1057

References inventory::add_item(), inv, inventory::volume(), and volume_capacity().

Referenced by player::add_or_drop_with_msg(), pickup_inventory_preset::get_denial(), give_item_to(), handle_harvest(), handle_problematic_pickup(), i_add_or_drop(), npc::mug_player(), pick_one_up(), conditional_t< T >::set_can_stow_weapon(), set_item_inventory(), and starting_inv().

◆ can_pick_volume() [2/2]

bool Character::can_pick_volume ( units::volume  volume) const

Definition at line 2897 of file character.cpp.

2898{
2899 // Might not be 100% true because some items restack to a very tiny bit less
2900 // but close enough not to matter
2901 return inv.volume() + volume <= volume_capacity();
2902}

References inv, inventory::volume(), and volume_capacity().

◆ can_pick_weight() [1/2]

bool Character::can_pick_weight ( const item it,
bool  safe = true 
) const

Definition at line 2904 of file character.cpp.

2905{
2906 return can_pick_weight( it.weight(), safe );
2907}
bool can_pick_weight(const item &it, bool safe=true) const
Definition: character.cpp:2904
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4838
void safe(player &p, const tripoint &examp)
Attempt to crack safe through audio-feedback manual lock manipulation.
Definition: iexamine.cpp:1409

References can_pick_weight(), iexamine::safe(), and item::weight().

Referenced by player::add_or_drop_with_msg(), can_pick_weight(), pickup_inventory_preset::get_denial(), give_item_to(), handle_harvest(), i_add_or_drop(), npc::mug_player(), pick_one_up(), and set_item_inventory().

◆ can_pick_weight() [2/2]

bool Character::can_pick_weight ( units::mass  weight,
bool  safe = true 
) const

Definition at line 2909 of file character.cpp.

2910{
2911 if( !safe ) {
2912 // Character can carry up to four times their maximum weight
2913 return ( weight_carried() + weight <= ( has_trait( trait_DEBUG_STORAGE ) ?
2914 units::mass_max : weight_capacity() * 4 ) );
2915 } else {
2916 return ( weight_carried() + weight <= weight_capacity() );
2917 }
2918}
static const trait_id trait_DEBUG_STORAGE("DEBUG_STORAGE")
constexpr mass mass_max
Definition: units_mass.h:27

References has_trait(), units::mass_max, iexamine::safe(), trait_DEBUG_STORAGE, weight_capacity(), and weight_carried().

◆ can_run()

bool Character::can_run ( )

source of truth of whether a Character can run

Definition at line 1332 of file character.cpp.

1333{
1334 return ( get_stamina() > get_stamina_max() * 0.1f ) && get_working_leg_count() >= 2;
1335}
int get_working_leg_count() const
Returns the number of functioning legs.
Definition: character.cpp:1308

References get_stamina(), get_stamina_max(), and get_working_leg_count().

Referenced by game::on_move_effects(), and avatar::set_movement_mode().

◆ can_swap()

ret_val< bool > Character::can_swap ( const item it) const

Check player capable of swapping the side of a worn item.

Parameters
itThing to be swapped

Definition at line 3167 of file character.cpp.

3168{
3169 if( it.has_flag( flag_POWERARMOR_MOD ) ) {
3170 int max_layer = 2;
3171 std::vector< std::pair< body_part, int > > mod_parts;
3172 body_part bp = num_bp;
3173 bodypart_str_id bpid;
3174 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ); ++i ) {
3175 bp = static_cast< body_part >( i );
3176 bpid = convert_bp( bp );
3177 if( it.get_covered_body_parts().test( bp ) && bpid->part_side != side::BOTH ) {
3178 mod_parts.emplace_back( bp, 0 );
3179 }
3180 }
3181 for( auto &elem : worn ) {
3182 for( std::pair< body_part, int > &mod_part : mod_parts ) {
3183 bpid = convert_bp( mod_part.first );
3184 if( elem.get_covered_body_parts().test( bpid->opposite_part->token ) &&
3185 elem.has_flag( flag_POWERARMOR_MOD ) ) {
3186 mod_part.second++;
3187 }
3188 }
3189 }
3190 for( std::pair< body_part, int > &mod_part : mod_parts ) {
3191 bpid = convert_bp( mod_part.first );
3192 if( mod_part.second >= max_layer ) {
3193 return ret_val<bool>::make_failure( _( "There is no space on the opposite side!" ) );
3194 }
3195 }
3196 }
3197
3199}
const bodypart_str_id & convert_bp(body_part bp)
Returns the new id for old token.
Definition: bodypart.cpp:185
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")
side part_side
Definition: bodypart.h:124
body_part token
Definition: bodypart.h:106
bodypart_str_id opposite_part
Definition: bodypart.h:122

References _, BOTH, convert_bp(), flag_POWERARMOR_MOD(), item::get_covered_body_parts(), item::has_flag(), ret_val< T >::make_failure(), ret_val< T >::make_success(), num_bp, body_part_type::opposite_part, body_part_type::part_side, body_part_set::test(), body_part_type::token, and worn.

Referenced by change_side().

◆ can_uninstall_bionic()

bool Character::can_uninstall_bionic ( const bionic_id b_id,
player installer,
bool  autodoc = false,
int  skill_level = -1 
)

Is The uninstallation possible.

Definition at line 1910 of file bionics.cpp.

1912{
1913 // If malfunctioning bionics doesn't have associated item it gets predefined difficulty
1914 int difficulty = BIONIC_NOITEM_DIFFICULTY;
1915 if( b_id->itype().is_valid() ) {
1916 const itype *type = &*b_id->itype();
1917 if( type->bionic ) {
1918 difficulty = type->bionic->difficulty;
1919 }
1920 }
1921
1922 if( !has_bionic( b_id ) ) {
1923 popup( _( "%s don't have this bionic installed." ), disp_name() );
1924 return false;
1925 }
1926
1927 if( b_id == bio_blaster ) {
1928 popup( _( "Removing %s Fusion Blaster Arm would leave %s with a useless stump." ),
1929 disp_name( true ), disp_name() );
1930 return false;
1931 }
1932
1933 if( ( b_id == bio_reactor ) || ( b_id == bio_advreactor ) ) {
1934 if( !g->u.query_yn(
1935 _( "WARNING: Removing a reactor may leave radioactive material! Remove anyway?" ) ) ) {
1936 return false;
1937 }
1938 }
1939
1940 for( const bionic_id &bid : get_bionics() ) {
1941 if( bid->is_included( b_id ) ) {
1942 popup( _( "%s must remove the %s bionic to remove the %s." ), installer.disp_name(),
1943 bid->name, b_id->name );
1944 return false;
1945 }
1946 }
1947
1948 if( b_id == bio_eye_optic ) {
1949 popup( _( "The Telescopic Lenses are part of %s eyes now. Removing them would leave %s blind." ),
1950 disp_name( true ), disp_name() );
1951 return false;
1952 }
1953
1954 // removal of bionics adds +2 difficulty over installation
1955 float adjusted_skill;
1956 if( autodoc ) {
1957 adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
1960 skill_level );
1961 } else {
1962 adjusted_skill = installer.bionics_adjusted_skill( skill_electronics,
1965 skill_level );
1966 }
1967 int chance_of_success = bionic_manip_cos( adjusted_skill, difficulty + 2 );
1968
1969 if( chance_of_success >= 100 ) {
1970 if( !g->u.query_yn(
1971 _( "Are you sure you wish to uninstall the selected bionic?" ),
1972 100 - chance_of_success ) ) {
1973 return false;
1974 }
1975 } else {
1976 if( !g->u.query_yn(
1977 _( "WARNING: %i percent chance of SEVERE damage to all body parts! Continue anyway?" ),
1978 ( 100 - static_cast<int>( chance_of_success ) ) ) ) {
1979 return false;
1980 }
1981 }
1982
1983 return true;
1984}
static const bionic_id bio_blaster("bio_blaster")
static const bionic_id bio_reactor("bio_reactor")
constexpr int BIONIC_NOITEM_DIFFICULTY
Definition: bionics.cpp:211
static const bionic_id bio_eye_optic("bio_eye_optic")
static const bionic_id bio_advreactor("bio_advreactor")
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:65
itype_id itype() const
Definition: bionics.cpp:249
Definition: itype.h:836

References _, iexamine::autodoc(), bio_advreactor, bio_blaster, bio_eye_optic, bio_reactor, bionic_manip_cos(), BIONIC_NOITEM_DIFFICULTY, bionics_adjusted_skill(), disp_name(), g, get_bionics(), has_bionic(), string_id< T >::is_valid(), bionic_data::itype(), bionic_data::name, popup(), skill_computer, skill_electronics, skill_firstaid, skill_mechanics, and type.

Referenced by iexamine::autodoc().

◆ can_unwield()

ret_val< bool > Character::can_unwield ( const item it) const

Check player capable of unwielding an item.

Parameters
itThing to be unwielded

Definition at line 3158 of file character.cpp.

3159{
3160 if( it.has_flag( "NO_UNWIELD" ) ) {
3161 return ret_val<bool>::make_failure( _( "You cannot unwield your %s." ), it.tname() );
3162 }
3163
3165}

References _, item::has_flag(), ret_val< T >::make_failure(), ret_val< T >::make_success(), and item::tname().

Referenced by apply_damage(), drop(), inv_dump(), game::inventory_item_menu(), player::unwield(), and game::wield().

◆ can_use()

bool Character::can_use ( const item it,
const item context = item() 
) const

Checks if character stats and skills meet minimum requirements for the item.

Prints an appropriate message if requirements not met.

Parameters
itItem we are checking
contextoptionally override effective item when checking contextual skills

Definition at line 2920 of file character.cpp.

2921{
2922 const auto &ctx = !context.is_null() ? context : it;
2923
2924 if( !meets_requirements( it, ctx ) ) {
2925 const std::string unmet( enumerate_unmet_requirements( it, ctx ) );
2926
2927 if( &it == &ctx ) {
2928 //~ %1$s - list of unmet requirements, %2$s - item name.
2929 add_msg_player_or_npc( m_bad, _( "You need at least %1$s to use this %2$s." ),
2930 _( "<npcname> needs at least %1$s to use this %2$s." ),
2931 unmet, it.tname() );
2932 } else {
2933 //~ %1$s - list of unmet requirements, %2$s - item name, %3$s - indirect item name.
2934 add_msg_player_or_npc( m_bad, _( "You need at least %1$s to use this %2$s with your %3$s." ),
2935 _( "<npcname> needs at least %1$s to use this %2$s with their %3$s." ),
2936 unmet, it.tname(), ctx.tname() );
2937 }
2938
2939 return false;
2940 }
2941
2942 return true;
2943}
std::string enumerate_unmet_requirements(const item &it, const item &context=item()) const
Returns a string of missed requirements (both stats and skills)
Definition: character.cpp:3379
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3467

References _, Creature::add_msg_player_or_npc(), enumerate_unmet_requirements(), item::is_null(), m_bad, meets_requirements(), and item::tname().

Referenced by can_use_heal_item(), player::gunmod_add(), ranged::gunmode_checks_common(), and player::toolmod_add().

◆ can_use_floor_warmth()

bool Character::can_use_floor_warmth ( ) const

Can the player lie down and cover self with blankets etc.

Definition at line 9454 of file character.cpp.

9455{
9456 return in_sleep_state() ||
9457 has_activity( activity_id( "ACT_WAIT" ) ) ||
9458 has_activity( activity_id( "ACT_WAIT_NPC" ) ) ||
9459 has_activity( activity_id( "ACT_WAIT_STAMINA" ) ) ||
9460 has_activity( activity_id( "ACT_AUTODRIVE" ) ) ||
9461 has_activity( activity_id( "ACT_READ" ) ) ||
9462 has_activity( activity_id( "ACT_SOCIALIZE" ) ) ||
9463 has_activity( activity_id( "ACT_MEDITATE" ) ) ||
9464 has_activity( activity_id( "ACT_FISH" ) ) ||
9465 has_activity( activity_id( "ACT_GAME" ) ) ||
9466 has_activity( activity_id( "ACT_HAND_CRANK" ) ) ||
9467 has_activity( activity_id( "ACT_HEATING" ) ) ||
9468 has_activity( activity_id( "ACT_VIBE" ) ) ||
9469 has_activity( activity_id( "ACT_TRY_SLEEP" ) ) ||
9470 has_activity( activity_id( "ACT_OPERATION" ) ) ||
9471 has_activity( activity_id( "ACT_TREE_COMMUNION" ) ) ||
9472 has_activity( activity_id( "ACT_EAT_MENU" ) ) ||
9473 has_activity( activity_id( "ACT_CONSUME_FOOD_MENU" ) ) ||
9474 has_activity( activity_id( "ACT_CONSUME_DRINK_MENU" ) ) ||
9475 has_activity( activity_id( "ACT_CONSUME_MEDS_MENU" ) ) ||
9476 has_activity( activity_id( "ACT_STUDY_SPELL" ) );
9477}
string_id< activity_type > activity_id
Definition: activity_type.h:15

References has_activity(), and in_sleep_state().

Referenced by update_bodytemp().

◆ can_use_heal_item()

bool Character::can_use_heal_item ( const item med) const

Check for mutation disallowing the use of an healing item.

Definition at line 424 of file mutation.cpp.

425{
426 const itype_id heal_id = med.typeId();
427
428 bool can_use = false;
429 bool got_restriction = false;
430
431 for( const trait_id &mut : get_mutations() ) {
432 if( !mut.obj().can_only_heal_with.empty() ) {
433 got_restriction = true;
434 }
435 if( mut.obj().can_only_heal_with.count( heal_id ) ) {
436 can_use = true;
437 break;
438 }
439 }
440 if( !got_restriction ) {
441 can_use = !med.has_flag( "CANT_HEAL_EVERYONE" );
442 }
443
444 if( !can_use ) {
445 for( const trait_id &mut : get_mutations() ) {
446 if( mut.obj().can_heal_with.count( heal_id ) ) {
447 can_use = true;
448 break;
449 }
450 }
451 }
452
453 return can_use;
454}
bool can_use(const item &it, const item &context=item()) const
Checks if character stats and skills meet minimum requirements for the item.
Definition: character.cpp:2920

References can_use(), get_mutations(), item::has_flag(), and item::typeId().

Referenced by activatable_inventory_preset::get_denial(), and heal_actor::use_healing_item().

◆ can_wear()

ret_val< bool > Character::can_wear ( const item it,
bool  with_equip_change = false 
) const

Check character capable of wearing an item.

Parameters
itThing to be worn
with_equip_changeIf true returns if it could be worn if things were taken off

Definition at line 2945 of file character.cpp.

2946{
2947 if( !it.is_armor() ) {
2948 return ret_val<bool>::make_failure( _( "Putting on a %s would be tricky." ), it.tname() );
2949 }
2950
2951 if( has_trait( trait_WOOLALLERGY ) && ( it.made_of( material_id( "wool" ) ) ||
2952 it.has_own_flag( "wooled" ) ) ) {
2953 return ret_val<bool>::make_failure( _( "Can't wear that, it's made of wool!" ) );
2954 }
2955
2956 if( it.is_filthy() && has_trait( trait_SQUEAMISH ) ) {
2957 return ret_val<bool>::make_failure( _( "Can't wear that, it's filthy!" ) );
2958 }
2959
2960 if( !it.has_flag( flag_OVERSIZE ) && !it.has_flag( flag_SEMITANGIBLE ) ) {
2961 for( const trait_id &mut : get_mutations() ) {
2962 const auto &branch = mut.obj();
2963 if( branch.conflicts_with_item( it ) ) {
2965 _( "Your %s mutation prevents you from wearing your %s." ) :
2966 _( "My %s mutation prevents me from wearing this %s." ), branch.name(),
2967 it.type_name() );
2968 }
2969 }
2970 if( it.covers( bp_head ) && !it.has_flag( flag_SEMITANGIBLE ) &&
2971 !it.made_of( material_id( "wool" ) ) && !it.made_of( material_id( "cotton" ) ) &&
2972 !it.made_of( material_id( "nomex" ) ) && !it.made_of( material_id( "leather" ) ) &&
2974 has_trait( trait_ANTLERS ) ) ) {
2975 return ret_val<bool>::make_failure( _( "Cannot wear a helmet over %s." ),
2976 ( has_trait( trait_HORNS_POINTED ) ? _( "horns" ) :
2977 ( has_trait( trait_ANTENNAE ) ? _( "antennae" ) : _( "antlers" ) ) ) );
2978 }
2979 }
2980
2981 if( it.has_flag( flag_SPLINT ) ) {
2982 bool need_splint = false;
2983 for( const bodypart_id &bp : get_all_body_parts() ) {
2984 if( !it.covers( bp->token ) ) {
2985 continue;
2986 }
2987 if( is_limb_broken( bp ) && !worn_with_flag( flag_SPLINT, bp ) ) {
2988 need_splint = true;
2989 break;
2990 }
2991 }
2992 if( !need_splint ) {
2994 _( "You don't have any broken limbs this could help." )
2995 : _( "%s doesn't have any broken limbs this could help." ), name );
2996 }
2997 }
2998
2999 if( it.has_flag( flag_RESTRICT_HANDS ) && !has_two_arms() ) {
3000 return ret_val<bool>::make_failure( ( is_player() ? _( "You don't have enough arms to wear that." )
3001 : string_format( _( "%s doesn't have enough arms to wear that." ), name ) ) );
3002 }
3003
3004 //Everything checked after here should be something that could be solved by changing equipment
3005 if( with_equip_change ) {
3007 }
3008
3009 if( it.is_power_armor() ) {
3010 for( auto &elem : worn ) {
3011 if( ( elem.get_covered_body_parts() & it.get_covered_body_parts() ).any() &&
3012 !elem.has_flag( flag_POWERARMOR_COMPATIBLE ) && !elem.is_power_armor() ) {
3013 return ret_val<bool>::make_failure( _( "Can't wear power armor over other gear!" ) );
3014 } else if( elem.has_flag( flag_POWERARMOR_EXO ) && it.has_flag( flag_POWERARMOR_EXO ) ) {
3015 return ret_val<bool>::make_failure( _( "Can't wear multiple exoskeletons!" ) );
3016 }
3017 }
3020 _( "You can only wear power armor components with power armor!" ) );
3021 }
3023 for( auto &elem : worn ) {
3024 if( elem.has_flag( flag_POWERARMOR_EXO ) &&
3025 ( elem.get_covered_body_parts() & it.get_covered_body_parts() ).any() ) {
3026 return ret_val<bool>::make_failure( _( "Can't wear externals over an exoskeleton!" ) );
3027 } else if( elem.has_flag( flag_POWERARMOR_EXTERNAL ) &&
3028 ( elem.get_covered_body_parts() & it.get_covered_body_parts() ).any() ) {
3029 return ret_val<bool>::make_failure( _( "Can't wear externals over one another!" ) );
3030 }
3031 }
3032 }
3033 if( it.has_flag( flag_POWERARMOR_MOD ) ) {
3034 int max_layer = 2;
3035 std::vector< std::pair< body_part, int > > mod_parts;
3036 std::vector< std::pair< body_part, bool > > attachments;
3037 body_part bp = num_bp;
3038 bodypart_str_id bpid;
3039 bool lhs = false;
3040 bool rhs = false;
3041 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ); ++i ) {
3042 bp = static_cast< body_part >( i );
3043 if( it.get_covered_body_parts().test( bp ) ) {
3044 mod_parts.emplace_back( bp, 0 );
3045 attachments.emplace_back( bp, false );
3046 }
3047 }
3048 for( auto &elem : worn ) {
3049 // To check if there's an external/exoskeleton for the mod to attach to.
3050 for( std::pair< body_part, bool > &attachment : attachments ) {
3051 if( elem.get_covered_body_parts().test( attachment.first ) &&
3052 ( elem.has_flag( flag_POWERARMOR_EXO ) || elem.has_flag( flag_POWERARMOR_EXTERNAL ) ) ) {
3053 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
3054 attachment.second = true;
3055 } else {
3056 attachment.second = true;
3057 }
3058 }
3059 }
3060 // To check how many mods are on a given part.
3061 for( std::pair< body_part, int > &mod_part : mod_parts ) {
3062 bpid = convert_bp( mod_part.first );
3063 if( elem.get_covered_body_parts().test( mod_part.first ) &&
3064 elem.has_flag( flag_POWERARMOR_MOD ) ) {
3065 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
3066 mod_part.second++;
3067 } else {
3068 mod_part.second++;
3069 }
3070 }
3071 }
3072 }
3073 for( std::pair< body_part, bool > &attachment : attachments ) {
3074 if( !attachment.second ) {
3075 return ret_val<bool>::make_failure( _( "Nothing to attach the mod to!" ) );
3076 }
3077 }
3078 for( std::pair< body_part, int > &mod_part : mod_parts ) {
3079 bpid = convert_bp( mod_part.first );
3080 if( static_cast< body_part >( mod_part.first ) == bp_torso ) {
3081 max_layer = 3;
3082 }
3083 if( mod_part.second >= max_layer ) {
3084 if( !it.is_sided() || bpid->part_side == side::BOTH ) {
3085 return ret_val<bool>::make_failure( _( "Can't wear any more mods on that body part!" ) );
3086 } else {
3087 if( bpid->part_side == side::LEFT ) {
3088 lhs = true;
3089 } else {
3090 rhs = true;
3091 }
3092 if( lhs && rhs ) {
3093 return ret_val<bool>::make_failure( _( "No more space for that mod!" ) );
3094 }
3095 }
3096 }
3097 }
3098 }
3099 } else {
3100 // Only headgear can be worn with power armor, except other power armor components.
3101 // You can't wear headgear if power armor helmet is already sitting on your head.
3102 for( auto &elem : worn ) {
3104 ( elem.get_covered_body_parts() & it.get_covered_body_parts() ).any() ) ) {
3105 return ret_val<bool>::make_failure( _( "Can't wear %s with power armor!" ), it.tname() );
3106 }
3107 }
3108 }
3109
3110 // Check if we don't have both hands available before wearing a briefcase, shield, etc. Also occurs if we're already wearing one.
3112 weapon.is_two_handed( *this ) ) ) {
3113 return ret_val<bool>::make_failure( ( is_player() ? _( "You don't have a hand free to wear that." )
3114 : string_format( _( "%s doesn't have a hand free to wear that." ), name ) ) );
3115 }
3116
3117 for( auto &i : worn ) {
3118 if( i.has_flag( flag_ONLY_ONE ) && i.typeId() == it.typeId() ) {
3119 return ret_val<bool>::make_failure( _( "Can't wear more than one %s!" ), it.tname() );
3120 }
3121 }
3122
3123 if( amount_worn( it.typeId() ) >= MAX_WORN_PER_TYPE ) {
3124 return ret_val<bool>::make_failure( _( "Can't wear %i or more %s at once." ),
3125 MAX_WORN_PER_TYPE + 1, it.tname( MAX_WORN_PER_TYPE + 1 ) );
3126 }
3127
3128 if( ( ( it.covers( bp_foot_l ) && is_wearing_shoes( side::LEFT ) ) ||
3129 ( it.covers( bp_foot_r ) && is_wearing_shoes( side::RIGHT ) ) ) &&
3130 ( !it.has_flag( flag_OVERSIZE ) || !it.has_flag( flag_OUTER ) ) && !it.has_flag( flag_SKINTIGHT ) &&
3131 !it.has_flag( flag_BELTED ) && !it.has_flag( flag_PERSONAL ) && !it.has_flag( flag_AURA ) &&
3132 !it.has_flag( flag_SEMITANGIBLE ) ) {
3133 // Checks to see if the player is wearing shoes
3134 return ret_val<bool>::make_failure( ( is_player() ? _( "You're already wearing footwear!" )
3135 : string_format( _( "%s is already wearing footwear!" ), name ) ) );
3136 }
3137
3138 if( it.covers( bp_head ) &&
3140 !it.has_flag( flag_PERSONAL ) && !it.is_power_armor() &&
3142 is_wearing_helmet() ) {
3144 ( is_player() ? _( "You can't wear that with other headgear!" )
3145 : string_format( _( "%s can't wear that with other headgear!" ), name ) ) );
3146 }
3147
3148 if( it.covers( bp_head ) && !it.has_flag( flag_SEMITANGIBLE ) &&
3150 ( head_cloth_encumbrance() + it.get_encumber( *this ) > 40 ) ) {
3151 return ret_val<bool>::make_failure( ( is_player() ? _( "You can't wear that much on your head!" )
3152 : string_format( _( "%s can't wear that much on their head!" ), name ) ) );
3153 }
3154
3156}
static const std::string flag_BELTED("BELTED")
static const trait_id trait_ANTLERS("ANTLERS")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const trait_id trait_HORNS_POINTED("HORNS_POINTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_POWERARMOR_COMPATIBLE("POWERARMOR_COMPATIBLE")
static const trait_id trait_ANTENNAE("ANTENNAE")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const std::string flag_OUTER("OUTER")
static const std::string flag_OVERSIZE("OVERSIZE")
static const std::string flag_ONLY_ONE("ONLY_ONE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
static const std::string flag_RESTRICT_HANDS("RESTRICT_HANDS")
static const trait_id trait_SQUEAMISH("SQUEAMISH")
bool is_wearing_power_armor(bool *hasHelmet=nullptr) const
Returns true if the character is wearing power armor.
Definition: character.cpp:3799
bool is_wearing_helmet() const
Returns true if the character is wearing something occupying the helmet slot.
Definition: character.cpp:8912
int amount_worn(const itype_id &id) const
Returns the amount of item ‘type’ that is currently worn.
Definition: character.cpp:2244
bool has_two_arms() const
Returns true if the player has two functioning arms.
Definition: character.cpp:1280
int head_cloth_encumbrance() const
Returns the total encumbrance of all SKINTIGHT and HELMET_COMPAT items coveringi the head.
Definition: character.cpp:8924
bool is_wearing_shoes(const side &which_side=side::BOTH) const
Returns true if the player is wearing something on their feet that is not SKINTIGHT.
Definition: character.cpp:8883
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:801
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:9802
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9672
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5630
bool is_armor() const
Definition: item.cpp:6548
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5636
bool is_two_handed(const Character &guy) const
Whether the character needs both hands to wield this item.
Definition: item.cpp:6248
static constexpr int MAX_WORN_PER_TYPE

References _, amount_worn(), BOTH, bp_foot_l, bp_foot_r, bp_head, bp_torso, convert_bp(), item::covers(), flag_AURA(), flag_BELTED(), flag_HELMET_COMPAT(), flag_ONLY_ONE(), flag_OUTER(), flag_OVERSIZE(), flag_PERSONAL(), flag_POWERARMOR_COMPATIBLE(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), flag_RESTRICT_HANDS(), flag_SEMITANGIBLE(), flag_SKINTIGHT(), flag_SPLINT(), Creature::get_all_body_parts(), item::get_covered_body_parts(), item::get_encumber(), get_mutations(), item::has_flag(), item::has_own_flag(), has_trait(), has_two_arms(), head_cloth_encumbrance(), item::is_armor(), item::is_filthy(), is_limb_broken(), Creature::is_player(), item::is_power_armor(), item::is_sided(), item::is_two_handed(), is_wearing_helmet(), is_wearing_power_armor(), is_wearing_shoes(), LEFT, item::made_of(), ret_val< T >::make_failure(), ret_val< T >::make_success(), MAX_WORN_PER_TYPE, name, num_bp, body_part_type::part_side, RIGHT, string_format(), body_part_set::test(), item::tname(), trait_ANTENNAE, trait_ANTLERS, trait_HORNS_POINTED, trait_SQUEAMISH, trait_WOOLALLERGY, item::type_name(), item::typeId(), weapon, wearing_something_on(), worn, and worn_with_flag().

Referenced by behavior::character_oracle_t::can_wear_warmer_clothes(), dispose_item(), wear_inventory_preset::get_denial(), give_item_to(), handle_problematic_pickup(), player::rate_action_wear(), starting_clothes(), player::use(), npc::wear_if_wanted(), and wear_item().

◆ cancel_activity()

void Character::cancel_activity ( )

Definition at line 9246 of file character.cpp.

9247{
9248 activity.canceled( *this );
9249 if( has_activity( ACT_MOVE_ITEMS ) && is_hauling() ) {
9250 stop_hauling();
9251 }
9252 if( has_activity( ACT_TRY_SLEEP ) ) {
9253 remove_value( "sleep_query" );
9254 }
9255 // Clear any backlog items that aren't auto-resume.
9256 for( auto backlog_item = backlog.begin(); backlog_item != backlog.end(); ) {
9257 if( backlog_item->auto_resume ) {
9258 backlog_item++;
9259 } else {
9260 backlog_item = backlog.erase( backlog_item );
9261 }
9262 }
9263 // act wait stamina interrupts an ongoing activity.
9264 // and automatically puts auto_resume = true on it
9265 // we don't want that to persist if there is another interruption.
9266 // and player moves elsewhere.
9267 if( has_activity( ACT_WAIT_STAMINA ) && !backlog.empty() &&
9268 backlog.front().auto_resume ) {
9269 backlog.front().auto_resume = false;
9270 }
9271 if( activity && activity.is_suspendable() ) {
9272 backlog.push_front( activity );
9273 }
9274 sfx::end_activity_sounds(); // kill activity sounds when canceled
9276}
static const activity_id ACT_TRY_SLEEP("ACT_TRY_SLEEP")
static const activity_id ACT_MOVE_ITEMS("ACT_MOVE_ITEMS")
static const activity_id ACT_WAIT_STAMINA("ACT_WAIT_STAMINA")
bool is_hauling() const
Definition: character.cpp:9198
void stop_hauling()
Definition: character.cpp:9189
void canceled(Character &who)
Performs activity-specific cleanup when Character::cancel_activity() is called.
bool is_suspendable() const
If this returns true, the action can be continued without starting from scratch again (see player::ba...
void end_activity_sounds()
Definition: sounds.cpp:1605

References ACT_MOVE_ITEMS, ACT_TRY_SLEEP, ACT_WAIT_STAMINA, activity, backlog, player_activity::canceled(), sfx::end_activity_sounds(), has_activity(), is_hauling(), player_activity::is_suspendable(), Creature::remove_value(), and stop_hauling().

Referenced by activity_on_turn_move_loot(), activity_on_turn_wear(), activity_handlers::adv_inventory_do_turn(), activity_handlers::armor_layers_do_turn(), activity_handlers::build_do_turn(), player::can_continue_craft(), game::cancel_activity_or_ignore_query(), game::cancel_activity_query(), activity_handlers::craft_do_turn(), autodrive_activity_actor::do_turn(), drop_activity_actor::do_turn(), stash_activity_actor::do_turn(), pickup_activity_actor::do_turn(), avatar_action::eat(), fall_asleep(), forced_dismount(), game::forced_door_closing(), item::handle_craft_failure(), mattack::pull_metal_weapon(), npc::reboot(), DefaultRemovePartHandler::removed(), autodrive_activity_actor::start(), activity_handlers::start_fire_do_turn(), and stop_hauling().

◆ cancel_stashed_activity()

void Character::cancel_stashed_activity ( )

◆ change_side() [1/2]

bool Character::change_side ( item it,
bool  interactive = true 
)

Swap side on which item is worn; returns false on fail.

If interactive is false, don't alert player or drain moves

Definition at line 3711 of file character.cpp.

3712{
3713 const auto ret = can_swap( it );
3714 if( !ret.success() ) {
3715 if( interactive ) {
3716 add_msg_if_player( m_info, "%s", ret.c_str() );
3717 }
3718 return false;
3719 }
3720
3721 if( !it.swap_side() ) {
3722 if( interactive ) {
3724 _( "You cannot swap the side on which your %s is worn." ),
3725 _( "<npcname> cannot swap the side on which their %s is worn." ),
3726 it.tname() );
3727 }
3728 return false;
3729 }
3730
3731 if( interactive ) {
3732 add_msg_player_or_npc( m_info, _( "You swap the side on which your %s is worn." ),
3733 _( "<npcname> swaps the side on which their %s is worn." ),
3734 it.tname() );
3735 }
3736
3737 mod_moves( -250 );
3739
3740 return true;
3741}
ret_val< bool > can_swap(const item &it) const
Check player capable of swapping the side of a worn item.
Definition: character.cpp:3167
bool swap_side()
Swap the side on which the item is worn.
Definition: item.cpp:829

References _, Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), can_swap(), m_info, Creature::mod_moves(), reset_encumbrance(), cata::hash64_detail::ret, item::swap_side(), and item::tname().

Referenced by npc::adjust_worn(), change_side(), game::inventory_item_menu(), and player::sort_armor().

◆ change_side() [2/2]

bool Character::change_side ( item_location loc,
bool  interactive = true 
)

Definition at line 3743 of file character.cpp.

3744{
3745 if( !loc || !is_worn( *loc ) ) {
3746 if( interactive ) {
3748 _( "You are not wearing that item." ),
3749 _( "<npcname> isn't wearing that item." ) );
3750 }
3751 return false;
3752 }
3753
3754 return change_side( *loc, interactive );
3755}
bool is_worn(const item &thing) const
Definition: character.h:1084
bool change_side(item &it, bool interactive=true)
Swap side on which item is worn; returns false on fail.
Definition: character.cpp:3711

References _, Creature::add_msg_player_or_npc(), change_side(), is_worn(), and m_info.

◆ check_and_recover_morale()

bool Character::check_and_recover_morale ( )

Checks permanent morale for consistency and recovers it when an inconsistency is found.

Definition at line 9141 of file character.cpp.

9142{
9143 player_morale test_morale;
9144
9145 for( const item &wit : worn ) {
9146 test_morale.on_item_wear( wit );
9147 }
9148
9149 for( const trait_id &mut : get_mutations() ) {
9150 test_morale.on_mutation_gain( mut );
9151 }
9152
9153 for( const auto &elem : *effects ) {
9154 for( const std::pair<const bodypart_str_id, effect> &_effect_it : elem.second ) {
9155 const effect &e = _effect_it.second;
9156 if( !e.is_removed() ) {
9157 test_morale.on_effect_int_change( e.get_id(), e.get_intensity(), e.get_bp() );
9158 }
9159 }
9160 }
9161
9162 test_morale.on_stat_change( "kcal", get_stored_kcal() );
9163 test_morale.on_stat_change( "thirst", get_thirst() );
9164 test_morale.on_stat_change( "fatigue", get_fatigue() );
9165 test_morale.on_stat_change( "pain", get_pain() );
9166 test_morale.on_stat_change( "pkill", get_painkiller() );
9167 test_morale.on_stat_change( "perceived_pain", get_perceived_pain() );
9168
9170
9171 if( !morale->consistent_with( test_morale ) ) {
9172 *morale = player_morale( test_morale ); // Recover consistency
9173 add_msg( m_debug, "%s morale was recovered.", disp_name( true ) );
9174 return false;
9175 }
9176
9177 return true;
9178}
int get_fatigue() const
Definition: character.cpp:4471
int get_thirst() const
Definition: character.cpp:4343
void apply_persistent_morale()
Ensures persistent morale effects are up-to-date.
Definition: character.cpp:9020
pimpl< effects_map > effects
Definition: creature.h:808
const efftype_id & get_id() const
Returns the effect's matching effect_type id.
Definition: effect.h:305
int get_intensity() const
Returns the intensity of an effect.
Definition: effect.cpp:849
const bodypart_str_id & get_bp() const
Returns the targeted body_part of the effect.
Definition: effect.cpp:835
bool is_removed() const
Returns if the effect is disabled and set up for removal.
Definition: effect.h:246
void on_item_wear(const item &it)
Definition: morale.cpp:935
void on_stat_change(const std::string &stat, int value)
Definition: morale.cpp:927
void on_effect_int_change(const efftype_id &eid, int intensity, const bodypart_str_id &bp=bodypart_str_id::NULL_ID())
Definition: morale.cpp:974
void on_mutation_gain(const trait_id &mid)
Definition: morale.cpp:917

References add_msg(), apply_persistent_morale(), disp_name(), Creature::effects, effect::get_bp(), get_fatigue(), effect::get_id(), effect::get_intensity(), get_mutations(), Creature::get_pain(), get_painkiller(), Creature::get_perceived_pain(), get_stored_kcal(), get_thirst(), effect::is_removed(), m_debug, morale, player_morale::on_effect_int_change(), player_morale::on_item_wear(), player_morale::on_mutation_gain(), player_morale::on_stat_change(), and worn.

Referenced by game::do_turn().

◆ check_item_encumbrance_flag()

void Character::check_item_encumbrance_flag ( )

Checks worn items for the "RESET_ENCUMBRANCE" flag, which indicates that encumbrance may have changed and require recalculating.

Definition at line 1844 of file character.cpp.

1845{
1846 bool update_required = check_encumbrance;
1847 for( auto &i : worn ) {
1848 if( !update_required && i.encumbrance_update_ ) {
1849 update_required = true;
1850 }
1851 i.encumbrance_update_ = false;
1852 }
1853
1854 if( update_required ) {
1856 }
1857}
bool check_encumbrance
Definition: character.h:2187

References check_encumbrance, reset_encumbrance(), and worn.

◆ check_mount_is_spooked()

bool Character::check_mount_is_spooked ( )

Definition at line 1102 of file character.cpp.

1103{
1104 if( !is_mounted() ) {
1105 return false;
1106 }
1107 // chance to spook per monster nearby:
1108 // base 1% per turn.
1109 // + 1% per square closer than 15 distanace. (1% - 15%)
1110 // * 2 if hostile monster is bigger than or same size as mounted creature.
1111 // -0.25% per point of dexterity (low -1%, average -2%, high -3%, extreme -3.5%)
1112 // -0.1% per point of strength ( low -0.4%, average -0.8%, high -1.2%, extreme -1.4% )
1113 // / 2 if horse has full tack and saddle.
1114 // Monster in spear reach monster and average stat (8) player on saddled horse, 14% -2% -0.8% / 2 = ~5%
1115 if( mounted_creature && mounted_creature->type->has_fear_trigger( mon_trigger::HOSTILE_CLOSE ) ) {
1116 const m_size mount_size = mounted_creature->get_size();
1117 const bool saddled = mounted_creature->has_effect( effect_saddled );
1118 for( const monster &critter : g->all_monsters() ) {
1119 double chance = 1.0;
1120 Attitude att = critter.attitude_to( *this );
1121 // actually too close now - horse might spook.
1122 if( att == A_HOSTILE && sees( critter ) && rl_dist( pos(), critter.pos() ) <= 10 ) {
1123 chance += 10 - rl_dist( pos(), critter.pos() );
1124 if( critter.get_size() >= mount_size ) {
1125 chance *= 2;
1126 }
1127 chance -= 0.25 * get_dex();
1128 chance -= 0.1 * get_str();
1129 if( saddled ) {
1130 chance /= 2;
1131 }
1132 chance = std::max( 1.0, chance );
1133 if( x_in_y( chance, 100.0 ) ) {
1135 return true;
1136 }
1137 }
1138 }
1139 }
1140 return false;
1141}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
static const efftype_id effect_saddled("monster_saddled")
void forced_dismount()
Definition: character.cpp:1148
Attitude
Simplified attitude towards any creature: hostile - hate, want to kill, etc.
Definition: creature.h:168
m_size
Definition: creature.h:57

Referenced by game::do_turn().

◆ check_mount_will_move()

bool Character::check_mount_will_move ( const tripoint dest_loc)

Definition at line 1084 of file character.cpp.

1085{
1086 if( !is_mounted() ) {
1087 return true;
1088 }
1089 if( mounted_creature && mounted_creature->type->has_fear_trigger( mon_trigger::HOSTILE_CLOSE ) ) {
1090 for( const monster &critter : g->all_monsters() ) {
1091 Attitude att = critter.attitude_to( *this );
1092 if( att == A_HOSTILE && sees( critter ) && rl_dist( pos(), critter.pos() ) <= 15 &&
1093 rl_dist( dest_loc, critter.pos() ) < rl_dist( pos(), critter.pos() ) ) {
1094 add_msg_if_player( _( "You fail to budge your %s!" ), mounted_creature->get_name() );
1095 return false;
1096 }
1097 }
1098 }
1099 return true;
1100}

References _, Creature::A_HOSTILE, Creature::add_msg_if_player(), g, HOSTILE_CLOSE, is_mounted(), mounted_creature, pos(), rl_dist(), and sees().

Referenced by avatar_action::move().

◆ check_needs_extremes()

void Character::check_needs_extremes ( )

Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings.

Intelligence slightly decreases occurrence of short naps when dead tired Intelligence slightly decreases occurrence of short naps when exhausted Perception slightly decreases occurrence of short naps when sleep deprived Perception slightly increases resilience against passing out from sleep deprivation

Definition at line 4979 of file character.cpp.

4980{
4981 // Check if we've overdosed... in any deadly way.
4982 if( get_stim() > 250 ) {
4983 add_msg_if_player( m_bad, _( "You have a sudden heart attack!" ) );
4984 g->events().send<event_type::dies_from_drug_overdose>( getID(), efftype_id() );
4985 set_part_hp_cur( bodypart_id( "torso" ), 0 );
4986 } else if( get_stim() < -200 || get_painkiller() > 240 ) {
4987 add_msg_if_player( m_bad, _( "Your breathing stops completely." ) );
4988 g->events().send<event_type::dies_from_drug_overdose>( getID(), efftype_id() );
4989 set_part_hp_cur( bodypart_id( "torso" ), 0 );
4990 } else if( has_effect( effect_jetinjector ) && get_effect_dur( effect_jetinjector ) > 40_minutes ) {
4991 if( !( has_trait( trait_NOPAIN ) ) ) {
4992 add_msg_if_player( m_bad, _( "Your heart spasms painfully and stops." ) );
4993 } else {
4994 add_msg_if_player( _( "Your heart spasms and stops." ) );
4995 }
4997 set_part_hp_cur( bodypart_id( "torso" ), 0 );
4998 } else if( get_effect_dur( effect_adrenaline ) > 50_minutes ) {
4999 add_msg_if_player( m_bad, _( "Your heart spasms and stops." ) );
5001 set_part_hp_cur( bodypart_id( "torso" ), 0 );
5002 } else if( get_effect_int( effect_drunk ) > 4 ) {
5003 add_msg_if_player( m_bad, _( "Your breathing slows down to a stop." ) );
5005 set_part_hp_cur( bodypart_id( "torso" ), 0 );
5006 }
5007
5008 // check if we've starved
5009 if( is_player() ) {
5010 if( get_stored_kcal() <= 0 ) {
5011 add_msg_if_player( m_bad, _( "You have starved to death." ) );
5012 g->events().send<event_type::dies_of_starvation>( getID() );
5013 set_part_hp_cur( bodypart_id( "torso" ), 0 );
5014 } else if( calendar::once_every( 6_hours ) ) {
5015 std::string category;
5016 if( get_kcal_percent() < 0.1f ) {
5017 category = "empty_starving";
5018 } else if( get_kcal_percent() < 0.25f ) {
5019 category = "empty_emaciated";
5020 } else if( get_kcal_percent() < 0.5f ) {
5021 category = "empty_malnutrition";
5022 } else if( get_kcal_percent() < 0.7f ) {
5023 category = "empty_low_cal";
5024 }
5025 if( !category.empty() ) {
5026 const translation message = SNIPPET.random_from_category( category ).value_or( translation() );
5028 }
5029
5030 }
5031 }
5032
5033 // Check if we're dying of thirst
5035 if( get_thirst() >= thirst_levels::dead ) {
5036 add_msg_if_player( m_bad, _( "You have died of dehydration." ) );
5037 g->events().send<event_type::dies_of_thirst>( getID() );
5038 set_part_hp_cur( bodypart_id( "torso" ), 0 );
5039 } else if( get_thirst() >= lerp( +thirst_levels::parched, +thirst_levels::dead, 0.333f ) &&
5040 calendar::once_every( 30_minutes ) ) {
5041 add_msg_if_player( m_warning, _( "Even your eyes feel dry…" ) );
5042 } else if( get_thirst() >= lerp( +thirst_levels::parched, +thirst_levels::dead, 0.666f ) &&
5043 calendar::once_every( 30_minutes ) ) {
5044 add_msg_if_player( m_warning, _( "You are THIRSTY!" ) );
5045 } else if( calendar::once_every( 30_minutes ) ) {
5046 add_msg_if_player( m_warning, _( "Your mouth feels so dry…" ) );
5047 }
5048 }
5049
5050 // Check if we're falling asleep, unless we're sleeping
5053 add_msg_if_player( m_bad, _( "Survivor sleep now." ) );
5055 mod_fatigue( -10 );
5056 fall_asleep();
5057 } else if( get_fatigue() >= 800 && calendar::once_every( 30_minutes ) ) {
5058 add_msg_if_player( m_warning, _( "Anywhere would be a good place to sleep…" ) );
5059 } else if( calendar::once_every( 30_minutes ) ) {
5060 add_msg_if_player( m_warning, _( "You feel like you haven't slept in days." ) );
5061 }
5062 }
5063
5064 // Even if we're not Exhausted, we really should be feeling lack/sleep earlier
5065 // Penalties start at Dead Tired and go from there
5067 if( get_fatigue() >= 700 ) {
5068 if( calendar::once_every( 30_minutes ) ) {
5069 add_msg_if_player( m_warning, _( "You're too physically tired to stop yawning." ) );
5070 add_effect( effect_lack_sleep, 30_minutes + 1_turns );
5071 }
5072 /** @EFFECT_INT slightly decreases occurrence of short naps when dead tired */
5073 if( one_in( 50 + int_cur ) ) {
5074 fall_asleep( 30_seconds );
5075 }
5076 } else if( get_fatigue() >= fatigue_levels::exhausted ) {
5077 if( calendar::once_every( 30_minutes ) ) {
5078 add_msg_if_player( m_warning, _( "How much longer until bedtime?" ) );
5079 add_effect( effect_lack_sleep, 30_minutes + 1_turns );
5080 }
5081 /** @EFFECT_INT slightly decreases occurrence of short naps when exhausted */
5082 if( one_in( 100 + int_cur ) ) {
5083 fall_asleep( 30_seconds );
5084 }
5085 } else if( get_fatigue() >= fatigue_levels::dead_tired && calendar::once_every( 30_minutes ) ) {
5086 add_msg_if_player( m_warning, _( "*yawn* You should really get some sleep." ) );
5087 add_effect( effect_lack_sleep, 30_minutes + 1_turns );
5088 }
5089 }
5090
5091 // Sleep deprivation kicks in if lack of sleep is avoided with stimulants or otherwise for long periods of time
5093 float sleep_deprivation_pct = sleep_deprivation / static_cast<float>
5095
5097 calendar::once_every( 60_minutes ) &&
5101 _( "Your mind feels tired. It's been a while since you've slept well." ) );
5102 mod_fatigue( 1 );
5105 _( "Your mind feels foggy from lack of good sleep, and your eyes keep trying to close against your will." ) );
5106 mod_fatigue( 5 );
5107
5108 if( one_in( 10 ) ) {
5109 mod_healthy_mod( -1, 0 );
5110 }
5113 _( "Your mind feels weary, and you dread every wakeful minute that passes. You crave sleep, and feel like you're about to collapse." ) );
5114 mod_fatigue( 10 );
5115
5116 if( one_in( 5 ) ) {
5117 mod_healthy_mod( -2, -20 );
5118 }
5121 _( "You haven't slept decently for so long that your whole body is screaming for mercy. It's a miracle that you're still awake, but it just feels like a curse now." ) );
5122 mod_fatigue( 40 );
5123
5124 mod_healthy_mod( -5, -50 );
5125 }
5126 // else you pass out for 20 hours, guaranteed
5127
5128 // Microsleeps are slightly worse if you're sleep deprived, but not by much. (chance: 1 in (75 + per_cur) at minor sleep deprivation)
5129 // Note: these can coexist with fatigue-related microsleeps
5130 /** @EFFECT_PER slightly decreases occurrence of short naps when sleep deprived */
5131 if( one_in( static_cast<int>( ( 1.0f - sleep_deprivation_pct ) * 75 + get_per() ) ) ) {
5132 fall_asleep( 30_seconds );
5133 }
5134
5135
5138 /** @EFFECT_PER slightly increases resilience against passing out from sleep deprivation */
5139 one_in( static_cast<int>( ( 1.0f - sleep_deprivation_pct ) * 100 ) + get_per() ) ) ) ) {
5141 _( "Your body collapses due to sleep deprivation, your neglected fatigue rushing back all at once, and you pass out on the spot." )
5142 , _( "<npcname> collapses to the ground from exhaustion." ) );
5144 set_fatigue( static_cast<int>( fatigue_levels::exhausted ) );
5145 }
5146
5148 fall_asleep( 20_hours );
5150 fall_asleep( 16_hours );
5151 } else {
5152 fall_asleep( 12_hours );
5153 }
5154 }
5155 }
5156}
constexpr T lerp(const T &min, const T &max, float t)
Linear interpolation: returns first argument if t is 0, second if t is 1, otherwise proportional to t...
Definition: cata_utility.h:155
static const efftype_id effect_lack_sleep("lack_sleep")
static const efftype_id effect_drunk("drunk")
static const efftype_id effect_adrenaline("adrenaline")
static const efftype_id effect_meth("meth")
static const efftype_id effect_jetinjector("jetinjector")
static const trait_id trait_NOPAIN("NOPAIN")
float get_kcal_percent() const
Definition: character.cpp:4338
virtual void set_fatigue(int nfatigue)
Definition: character.cpp:4456
void fall_asleep()
Adds "sleep" to the player.
Definition: character.cpp:9286
virtual void mod_fatigue(int nfatigue)
Definition: character.cpp:4446
int get_stim() const
Definition: character.cpp:7175
virtual void mod_healthy_mod(int nhealthy_mod, int cap)
Definition: character.cpp:4274
int get_sleep_deprivation() const
Definition: character.cpp:4476
virtual int get_per() const
Definition: character.cpp:4088
void set_part_hp_cur(const bodypart_id &id, int set)
Definition: creature.cpp:1575
time_duration get_effect_dur(const efftype_id &eff_id, body_part bp=num_bp) const
Returns the duration of the matching effect.
Definition: creature.cpp:1241
cata::optional< translation > random_from_category(const std::string &cat) const
Returns a random snippet out of the given category.
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
@ m_warning
Definition: enums.h:257
@ falls_asleep_from_exhaustion
@ dies_from_drug_overdose
@ dies_of_starvation
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490
std::string message
Definition: mapgen.cpp:403
snippet_library SNIPPET

References _, Creature::add_effect(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), dead, dead_tired, dies_from_drug_overdose, dies_of_starvation, dies_of_thirst, effect_adrenaline, effect_drunk, effect_jetinjector, effect_lack_sleep, effect_meth, efftype_id, exhausted, fall_asleep(), falls_asleep_from_exhaustion, g, Creature::get_effect_dur(), Creature::get_effect_int(), get_fatigue(), get_kcal_percent(), get_painkiller(), get_per(), get_sleep_deprivation(), get_stim(), get_stored_kcal(), get_thirst(), getID(), harmless, Creature::has_effect(), has_trait(), in_sleep_state(), int_cur, Creature::is_player(), lerp(), m_bad, m_warning, major, massive, mapgen_defer::message, minor, mod_fatigue(), mod_healthy_mod(), calendar::once_every(), one_in(), parched, snippet_library::random_from_category(), serious, set_fatigue(), Creature::set_part_hp_cur(), sleep_deprivation, SNIPPET, and trait_NOPAIN.

Referenced by update_body().

◆ check_outbounds_activity()

bool Character::check_outbounds_activity ( const player_activity act,
bool  check_only = false 
)

Definition at line 996 of file character.cpp.

997{
998 map &here = get_map();
999 if( ( act.placement != tripoint_zero && act.placement != tripoint_min &&
1000 !here.inbounds( here.getlocal( act.placement ) ) ) || ( !act.coords.empty() &&
1001 !here.inbounds( here.getlocal( act.coords.back() ) ) ) ) {
1002 if( is_npc() && !check_only ) {
1003 // stash activity for when reloaded.
1005 if( !backlog.empty() ) {
1007 }
1009 }
1011 "npc %s at pos %d %d, activity target is not inbounds at %d %d therefore activity was stashed",
1012 disp_name(), pos().x, pos().y, act.placement.x, act.placement.y );
1013 return true;
1014 }
1015 return false;
1016}
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8220
virtual bool inbounds(const tripoint &p) const
Definition: map.cpp:7711
static constexpr tripoint tripoint_zero
Definition: point.h:273
static constexpr tripoint tripoint_min
Definition: point.h:318

References act, activity, add_msg(), backlog, disp_name(), get_map(), map::getlocal(), map::inbounds(), Creature::is_npc(), m_debug, pos(), stashed_outbounds_activity, stashed_outbounds_backlog, tripoint_min, and tripoint_zero.

Referenced by player_activity::do_turn(), and npc::move().

◆ clairvoyance()

int Character::clairvoyance ( ) const

Returns the distance the player can see through walls.

Definition at line 802 of file character.cpp.

803{
805 return MAX_CLAIRVOYANCE;
806 }
807
809 return 8;
810 }
811
813 return 3;
814 }
815
816 // 0 would mean we have clairvoyance of own tile
817 return -1;
818}
#define MAX_CLAIRVOYANCE
Definition: character.h:84
@ VISION_CLAIRVOYANCE_PLUS
Definition: character.h:95
@ VISION_CLAIRVOYANCE
Definition: character.h:94
@ VISION_CLAIRVOYANCE_SUPER
Definition: character.h:96
std::bitset< NUM_VISION_MODES > vision_mode_cache
Definition: character.h:2108

References MAX_CLAIRVOYANCE, VISION_CLAIRVOYANCE, VISION_CLAIRVOYANCE_PLUS, VISION_CLAIRVOYANCE_SUPER, and vision_mode_cache.

Referenced by sees().

◆ clear_bionics()

void Character::clear_bionics ( )

Remove all bionics.

Definition at line 2666 of file bionics.cpp.

2667{
2668 my_bionics->clear();
2669}

References my_bionics.

◆ clear_destination()

◆ clear_destination_activity()

void Character::clear_destination_activity ( )

Definition at line 1023 of file character.cpp.

1024{
1026}
player_activity destination_activity
Definition: character.h:2172

References destination_activity.

Referenced by clear_destination().

◆ clear_miss_reasons()

void Character::clear_miss_reasons ( )

Clears the list of reasons for why the player would miss a melee attack.

Definition at line 324 of file melee.cpp.

325{
326 melee_miss_reasons.clear();
327}

References melee_miss_reasons.

Referenced by player::process_turn().

◆ clear_morale()

void Character::clear_morale ( )

Definition at line 9131 of file character.cpp.

9132{
9133 morale->clear();
9134}

References morale.

◆ clear_mutations()

void Character::clear_mutations ( )

Empties the trait and mutations lists.

Definition at line 2840 of file newcharacter.cpp.

2841{
2842 while( !my_traits.empty() ) {
2843 toggle_trait( *my_traits.begin() );
2844 }
2845 while( !my_mutations.empty() ) {
2846 unset_mutation( my_mutations.begin()->first );
2847 }
2848 cached_mutations.clear();
2849}
std::vector< const mutation_branch * > cached_mutations
Pointers to mutation branches in my_mutations.
Definition: character.h:2099
void unset_mutation(const trait_id &)
Definition: mutation.cpp:167
std::unordered_set< trait_id > my_traits
Contains mutation ids of the base traits.
Definition: character.h:2095

References cached_mutations, my_mutations, my_traits, toggle_trait(), and unset_mutation().

Referenced by npc::randomize(), and reset_scenario().

◆ compute_effective_nutrients()

nutrients Character::compute_effective_nutrients ( const item comest) const

Definition at line 328 of file consumption.cpp.

329{
330 if( !comest.is_comestible() ) {
331 return {};
332 }
333
334 // if item has components, will derive calories from that instead.
335 if( !comest.components.empty() && !comest.has_flag( flag_NUTRIENT_OVERRIDE ) ) {
336 nutrients tally{};
337 for( const item &component : comest.components ) {
338 nutrients component_value =
340 if( component.has_flag( flag_BYPRODUCT ) ) {
341 tally -= component_value;
342 } else {
343 tally += component_value;
344 }
345 }
346 return tally / comest.recipe_charges;
347 } else {
348 return compute_default_effective_nutrients( comest, *this );
349 }
350}
nutrients compute_effective_nutrients(const item &) const
std::list< item > components
Definition: item.h:2158
int recipe_charges
Definition: item.h:2198
static nutrients compute_default_effective_nutrients(const item &comest, const Character &you, const cata::flat_set< std::string > &extra_flags={})
static const std::string flag_NUTRIENT_OVERRIDE("NUTRIENT_OVERRIDE")
static const std::string flag_BYPRODUCT("BYPRODUCT")

References item::components, compute_default_effective_nutrients(), compute_effective_nutrients(), flag_BYPRODUCT(), flag_NUTRIENT_OVERRIDE(), item::has_flag(), item::is_comestible(), and item::recipe_charges.

Referenced by comestible_inventory_preset::comestible_inventory_preset(), compute_effective_nutrients(), consume_effects(), player::eat(), find_auto_consume(), nutrition_for(), and will_eat().

◆ compute_nutrient_range() [1/2]

std::pair< nutrients, nutrients > Character::compute_nutrient_range ( const item comest,
const recipe_id recipe_i,
const cata::flat_set< std::string > &  extra_flags = {} 
) const

Get calorie & vitamin contents for a comestible, taking into account character traits.

Get range of possible nutrient content, for a particular recipe, depending on choice of ingredients

Definition at line 354 of file consumption.cpp.

357{
358 if( !comest.is_comestible() ) {
359 return {};
360 }
361
362 // if item has components, will derive calories from that instead.
363 if( comest.has_flag( flag_NUTRIENT_OVERRIDE ) ) {
365 return { result, result };
366 }
367
368 nutrients tally_min;
369 nutrients tally_max;
370
371 const recipe &rec = *recipe_i;
372
373 cata::flat_set<std::string> our_extra_flags = extra_flags;
374
375 if( rec.hot_result() ) {
376 our_extra_flags.insert( flag_COOKED );
377 }
378
379 const requirement_data requirements = rec.simple_requirements();
380 const requirement_data::alter_item_comp_vector &component_requirements =
381 requirements.get_components();
382
383 for( const std::vector<item_comp> &component_options : component_requirements ) {
384 nutrients this_min;
385 nutrients this_max;
386 bool first = true;
387 for( const item_comp &component_option : component_options ) {
388 std::pair<nutrients, nutrients> component_option_range =
389 compute_nutrient_range( component_option.type, our_extra_flags );
390 component_option_range.first *= component_option.count;
391 component_option_range.second *= component_option.count;
392
393 if( first ) {
394 std::tie( this_min, this_max ) = component_option_range;
395 first = false;
396 } else {
397 this_min.min_in_place( component_option_range.first );
398 this_max.max_in_place( component_option_range.second );
399 }
400 }
401 tally_min += this_min;
402 tally_max += this_max;
403 }
404
405 for( const std::pair<const itype_id, int> &byproduct : rec.byproducts ) {
406 item byproduct_it( byproduct.first, calendar::turn, byproduct.second );
407 nutrients byproduct_nutr = compute_default_effective_nutrients( byproduct_it, *this );
408 tally_min -= byproduct_nutr;
409 tally_max -= byproduct_nutr;
410 }
411
412 int charges = comest.count();
413 return { tally_min / charges, tally_max / charges };
414}
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:5854
Definition: recipe.h:35
const requirement_data & simple_requirements() const
Fetch combined requirement data (inline and via "using" syntax).
Definition: recipe.h:67
bool hot_result() const
Definition: recipe.cpp:774
std::map< itype_id, int > byproducts
Definition: recipe.h:105
static const std::string flag_COOKED("COOKED")
void min_in_place(const nutrients &r)
Replace the values here with the minimum (or maximum) of themselves and the corresponding values take...
Definition: stomach.cpp:12
void max_in_place(const nutrients &r)
Definition: stomach.cpp:29
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_item_comp_vector & get_components() const
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223

References recipe::byproducts, compute_default_effective_nutrients(), compute_nutrient_range(), item::count(), flag_COOKED(), flag_NUTRIENT_OVERRIDE(), requirement_data::get_components(), item::has_flag(), recipe::hot_result(), cata::flat_set< T, Compare, Data >::insert(), item::is_comestible(), nutrients::max_in_place(), nutrients::min_in_place(), recipe::simple_requirements(), and calendar::turn.

Referenced by compute_nutrient_range().

◆ compute_nutrient_range() [2/2]

std::pair< nutrients, nutrients > Character::compute_nutrient_range ( const itype_id comest_id,
const cata::flat_set< std::string > &  extra_flags = {} 
) const

Same, but across arbitrary recipes.

Definition at line 418 of file consumption.cpp.

420{
421 const itype *comest = &*comest_id;
422 if( !comest->comestible ) {
423 return {};
424 }
425
426 item comest_it( comest, calendar::turn, 1 );
427 // The default nutrients are always a possibility
428 nutrients min_nutr = compute_default_effective_nutrients( comest_it, *this, extra_flags );
429
430 if( comest->has_flag( flag_NUTRIENT_OVERRIDE ) ||
431 recipe_dict.is_item_on_loop( comest->get_id() ) ) {
432 return { min_nutr, min_nutr };
433 }
434
435 nutrients max_nutr = min_nutr;
436
437 for( const recipe_id &rec : comest->recipes ) {
438 nutrients this_min;
439 nutrients this_max;
440
441 item result_it = rec->create_result();
442 if( result_it.contents.num_item_stacks() == 1 ) {
443 const item alt_result = result_it.contents.front();
444 if( alt_result.typeId() == comest_it.typeId() ) {
445 result_it = alt_result;
446 }
447 }
448 if( result_it.typeId() != comest_it.typeId() ) {
449 debugmsg( "When creating recipe result expected %s, got %s\n",
450 comest_it.typeId().str(), result_it.typeId().str() );
451 }
452 std::tie( this_min, this_max ) = compute_nutrient_range( result_it, rec, extra_flags );
453 min_nutr.min_in_place( this_min );
454 max_nutr.max_in_place( this_max );
455 }
456
457 return { min_nutr, max_nutr };
458}
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
bool is_item_on_loop(const itype_id &) const
item create_result() const
Definition: recipe.cpp:423
recipe_dictionary recipe_dict
cata::value_ptr< islot_comestible > comestible
Definition: itype.h:848
std::vector< recipe_id > recipes
What recipes can make this item.
Definition: itype.h:1014
bool has_flag(const std::string &flag) const
Definition: itype.cpp:71
const itype_id & get_id() const
Definition: itype.h:1070

References itype::comestible, compute_default_effective_nutrients(), compute_nutrient_range(), item::contents, recipe::create_result(), debugmsg, flag_NUTRIENT_OVERRIDE(), item_contents::front(), itype::get_id(), itype::has_flag(), recipe_dictionary::is_item_on_loop(), nutrients::max_in_place(), nutrients::min_in_place(), item_contents::num_item_stacks(), recipe_dict, itype::recipes, string_id< T >::str(), calendar::turn, and item::typeId().

◆ conduct_blood_analysis()

void Character::conduct_blood_analysis ( ) const

Definition at line 2027 of file character.cpp.

2028{
2029 std::vector<std::string> effect_descriptions;
2030 std::vector<nc_color> colors;
2031
2032 for( auto &elem : *effects ) {
2033 if( elem.first->get_blood_analysis_description().empty() ) {
2034 continue;
2035 }
2036 effect_descriptions.emplace_back( elem.first->get_blood_analysis_description() );
2037 colors.emplace_back( elem.first->get_rating() == e_good ? c_green : c_red );
2038 }
2039
2040 const int win_w = 46;
2041 size_t win_h = 0;
2043 ui_adaptor ui;
2044 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
2045 win_h = std::min( static_cast<size_t>( TERMY ),
2046 std::max<size_t>( 1, effect_descriptions.size() ) + 2 );
2047 w = catacurses::newwin( win_h, win_w,
2048 point( ( TERMX - win_w ) / 2, ( TERMY - win_h ) / 2 ) );
2049 ui.position_from_window( w );
2050 } );
2051 ui.mark_resize();
2052 ui.on_redraw( [&]( const ui_adaptor & ) {
2053 draw_border( w, c_red, string_format( " %s ", _( "Blood Test Results" ) ) );
2054 if( effect_descriptions.empty() ) {
2055 trim_and_print( w, point( 2, 1 ), win_w - 3, c_white, _( "No effects." ) );
2056 } else {
2057 for( size_t line = 1; line < ( win_h - 1 ) && line <= effect_descriptions.size(); ++line ) {
2058 trim_and_print( w, point( 2, line ), win_w - 3, colors[line - 1], effect_descriptions[line - 1] );
2059 }
2060 }
2061 wnoutrefresh( w );
2062 } );
2063 input_context ctxt( "BLOOD_TEST_RESULTS" );
2064 ctxt.register_action( "CONFIRM" );
2065 ctxt.register_action( "QUIT" );
2066 ctxt.register_action( "HELP_KEYBINDINGS" );
2067 bool stop = false;
2068 // Display new messages
2069 g->invalidate_main_ui_adaptor();
2070 while( !stop ) {
2072 const std::string action = ctxt.handle_input();
2073 if( action == "CONFIRM" || action == "QUIT" ) {
2074 stop = true;
2075 }
2076 }
2077}
A wrapper over a pointer to a curses window.
Definition: cursesdef.h:55
Represents a context in which a set of actions can be performed.
Definition: input.h:382
@ action
Definition: dialogue.h:36
@ e_good
Definition: effect.h:29
void line(map *m, const ter_id &type, const point &p1, const point &p2)
Definition: mapgen.cpp:6455
std::string colors()
Definition: path_info.cpp:146
window newwin(int nlines, int ncols, const point &begin)
Definition: ncurses_def.cpp:34
void wnoutrefresh(const window &win)
Definition: ncurses_def.cpp:43
void redraw()
Definition: ui_manager.cpp:285
Definition: overmap_ui.h:17
int TERMX
Definition: output.cpp:47
int TERMY
Definition: output.cpp:48
void trim_and_print(const catacurses::window &w, const point &begin, const int width, const nc_color &base_color, const std::string &text, const report_color_error color_error)
Prints a single line of text.
Definition: output.cpp:214
void draw_border(const catacurses::window &w, nc_color border_color, const std::string &title, nc_color title_color)
Definition: output.cpp:575

References _, action, c_green, c_red, c_white, PATH_INFO::colors(), draw_border(), e_good, Creature::effects, g, input_context::handle_input(), line(), catacurses::newwin(), ui_manager::redraw(), input_context::register_action(), string_format(), TERMX, TERMY, trim_and_print(), and catacurses::wnoutrefresh().

Referenced by activate_bionic(), and iexamine::autodoc().

◆ consume_charges()

bool Character::consume_charges ( item used,
int  qty 
)

Consume charges of a tool or comestible item, potentially destroying it in the process.

Parameters
useditem consuming the charges
qtynumber of charges to consume which must be non-zero
Returns
true if item was destroyed

Definition at line 7529 of file character.cpp.

7530{
7531 if( qty < 0 ) {
7532 debugmsg( "Tried to consume negative charges" );
7533 return false;
7534 }
7535
7536 if( qty == 0 ) {
7537 return false;
7538 }
7539
7540 if( !used.is_tool() && !used.is_food() && !used.is_medication() ) {
7541 debugmsg( "Tried to consume charges for non-tool, non-food, non-med item" );
7542 return false;
7543 }
7544
7545 // Consume comestibles destroying them if no charges remain
7546 if( used.is_food() || used.is_medication() ) {
7547 used.charges -= qty;
7548 if( used.charges <= 0 ) {
7549 i_rem( &used );
7550 return true;
7551 }
7552 return false;
7553 }
7554
7555 // Tools which don't require ammo are instead destroyed
7556 if( used.is_tool() && !used.ammo_required() ) {
7557 i_rem( &used );
7558 return true;
7559 }
7560
7561 if( used.is_power_armor() ) {
7562 if( used.charges >= qty ) {
7563 used.ammo_consume( qty, pos() );
7564 } else if( as_player()->can_interface_armor() && has_charges( itype_bio_armor, qty ) ) {
7566 } else {
7567 use_charges( itype_UPS, qty );
7568 }
7569 }
7570
7571 // USE_UPS never occurs on base items but is instead added by the UPS tool mod
7572 if( used.has_flag( flag_USE_UPS ) ) {
7573 // With the new UPS system, we'll want to use any charges built up in the tool before pulling from the UPS
7574 // The usage of the item was already approved, so drain item if possible, otherwise use UPS
7575 if( used.charges >= qty ) {
7576 used.ammo_consume( qty, pos() );
7577 } else {
7578 use_charges( itype_UPS, qty );
7579 }
7580 } else {
7581 used.ammo_consume( std::min( qty, used.ammo_remaining() ), pos() );
7582 }
7583 return false;
7584}
static const std::string flag_USE_UPS("USE_UPS")
static const itype_id itype_bio_armor("bio_armor")
std::list< item > use_charges(const itype_id &what, int qty, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: character.cpp:9672
bool is_tool() const
Definition: item.cpp:6797
bool is_food() const
Definition: item.cpp:6436
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7318

References item::ammo_consume(), item::ammo_remaining(), item::ammo_required(), Creature::as_player(), item::charges, debugmsg, flag_USE_UPS(), has_charges(), item::has_flag(), i_rem(), item::is_food(), item::is_medication(), item::is_power_armor(), item::is_tool(), itype_bio_armor, itype_UPS, pos(), and use_charges().

Referenced by chop_plank_activity(), chop_tree_activity(), feedpet(), activity_handlers::firstaid_finish(), npc::heal_player(), npc::heal_self(), invoke_item(), activity_handlers::jackhammer_finish(), petfood(), activity_handlers::pickaxe_finish(), npc::pretend_heal(), activity_handlers::repair_item_finish(), activity_handlers::shear_finish(), and activity_handlers::start_fire_finish().

◆ consume_effects()

bool Character::consume_effects ( item food)

Handles the effects of consuming an item.

Definition at line 1160 of file consumption.cpp.

1161{
1162 if( !food.is_comestible() ) {
1163 debugmsg( "called Character::consume_effects with non-comestible" );
1164 return false;
1165 }
1166
1167 if( has_trait( trait_THRESH_PLANT ) && food.type->can_use( "PLANTBLECH" ) ) {
1168 // Was used to cap nutrition and thirst, but no longer does this
1169 return false;
1170 }
1173 // No good can come of this.
1174 return false;
1175 }
1176
1177 const auto &comest = *food.get_comestible();
1178
1179 // Rotten food causes health loss
1180 const float relative_rot = food.get_relative_rot();
1181 if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) &&
1183 const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
1184 // ~-1 health per 1 nutrition at halfway-rotten-away, ~0 at "just got rotten"
1185 // But always round down
1186 int h_loss = -rottedness * comest.get_default_nutr();
1187 mod_healthy_mod( h_loss, -200 );
1188 add_msg( m_debug, "%d health from %0.2f%% rotten food", h_loss, rottedness );
1189 }
1190
1191 // Used in hibernation messages.
1192 const auto nutr = nutrition_for( food );
1193 const bool skip_health = has_trait( trait_PROJUNK2 ) && comest.healthy < 0;
1194 // We can handle junk just fine
1195 if( !skip_health ) {
1196 modify_health( comest );
1197 }
1198 modify_stimulation( comest );
1199 modify_fatigue( comest );
1200 modify_radiation( comest );
1201 modify_addiction( comest );
1202 modify_morale( food, nutr );
1203
1204 // Moved here and changed a bit - it was too complex
1205 // Incredibly minor stuff like this shouldn't require complexity
1206 if( !is_npc() && has_trait( trait_SLIMESPAWNER ) &&
1209 _( "You feel as though you're going to split open! In a good way?" ) );
1210 mod_pain( 5 );
1211 int numslime = 1;
1212 for( int i = 0; i < numslime; i++ ) {
1213 if( monster *const slime = g->place_critter_around( mon_player_blob, pos(), 1 ) ) {
1214 slime->friendly = -1;
1215 }
1216 }
1217 mod_stored_kcal( -400 );
1218 mod_thirst( 40 );
1219 //~ slimespawns have *small voices* which may be the Nice equivalent
1220 //~ of the Rat King's ALL CAPS invective. Probably shared-brain telepathy.
1221 add_msg_if_player( m_good, _( "hey, you look like me! let's work together!" ) );
1222 }
1223
1224 // Set up food for ingestion
1225 const item &contained_food = food.is_container() ? food.get_contained() : food;
1226 food_summary ingested{
1227 compute_effective_nutrients( contained_food )
1228 };
1229 // Maybe move tapeworm to digestion
1230 if( has_effect( effect_tapeworm ) ) {
1231 ingested.nutr /= 2;
1232 }
1233
1234 int excess_kcal = get_stored_kcal() + stomach.get_calories() + ingested.nutr.kcal -
1236
1237 // Moved hypermetabolism check here to prevent it being gimped by various bloating/vomit problems.
1238 if( excess_kcal > 0 && has_trait( trait_EATHEALTH ) ) {
1239 healall( roll_remainder( excess_kcal / 50.0f ) );
1240 mod_stored_kcal( -excess_kcal );
1241 excess_kcal = 0;
1242 }
1243
1244 int excess_quench = -( get_thirst() - comest.quench );
1245 stomach.ingest( ingested );
1246 mod_thirst( -contained_food.type->comestible->quench );
1247
1248
1249 if( ( excess_kcal > 0 || excess_quench > 0 ) && !food.has_flag( flag_NO_BLOAT ) ) {
1250 add_effect( effect_bloated, 5_minutes );
1251 }
1252
1253 return true;
1254}
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:145
void modify_addiction(const islot_comestible &comest)
Used to apply addiction modifications from food and medication.
void modify_stimulation(const islot_comestible &comest)
Used to apply stimulation modifications from food and medication.
void modify_morale(item &food, int nutr=0)
Used to apply morale modifications from food and medication.
void modify_radiation(const islot_comestible &comest)
Used to apply radiation from food and medication.
virtual void mod_thirst(int nthirst)
Definition: character.cpp:4430
stomach_contents stomach
Definition: character.h:1535
void modify_health(const islot_comestible &comest)
Used to apply health modifications from food and medication.
void healall(int dam)
Heals all body parts for dam.
Definition: character.cpp:8663
void modify_fatigue(const islot_comestible &comest)
Used to apply fatigue modifications from food and medication.
bool is_container() const
Whether this is container.
Definition: item.cpp:6563
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5414
const item & get_contained() const
Return a contained item (if any and only one).
Definition: item.cpp:6884
void ingest(const food_summary &ingested)
Directly adds food to stomach contents.
Definition: stomach.cpp:126
int get_calories() const
Definition: stomach.cpp:179
static const trait_id trait_SLIMESPAWNER("SLIMESPAWNER")
static const mtype_id mon_player_blob("mon_player_blob")
static const trait_id trait_THRESH_PLANT("THRESH_PLANT")
static const bionic_id bio_digestion("bio_digestion")
static const efftype_id effect_tapeworm("tapeworm")
static const trait_id trait_PROJUNK2("PROJUNK2")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const efftype_id effect_bloated("bloated")
static const trait_id trait_EATHEALTH("EATHEALTH")
static const trait_id trait_SAPROPHAGE("SAPROPHAGE")
static const std::string flag_NO_BLOAT("NO_BLOAT")
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:86

References _, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), bio_digestion, itype::can_use(), clamp(), itype::comestible, compute_effective_nutrients(), debugmsg, effect_bloated, effect_tapeworm, flag_NO_BLOAT(), g, stomach_contents::get_calories(), item::get_comestible(), item::get_contained(), item::get_relative_rot(), get_stored_kcal(), get_thirst(), item::has_any_flag(), has_bionic(), Creature::has_effect(), item::has_flag(), has_trait(), healall(), herbivore_blacklist(), stomach_contents::ingest(), item::is_comestible(), item::is_container(), Creature::is_npc(), m_debug, m_good, m_mixed, max_stored_kcal(), mod_healthy_mod(), Creature::mod_pain(), mod_stored_kcal(), mod_thirst(), modify_addiction(), modify_fatigue(), modify_health(), modify_morale(), modify_radiation(), modify_stimulation(), mon_player_blob, nutrition_for(), pos(), roll_remainder(), slaked, stomach, trait_EATHEALTH, trait_HERBIVORE, trait_PROJUNK2, trait_RUMINANT, trait_SAPROPHAGE, trait_SAPROVORE, trait_SLIMESPAWNER, trait_THRESH_PLANT, and item::type.

Referenced by player::consume_med(), player::eat(), iuse::ecig(), and try_consume().

◆ consume_remote_fuel()

int Character::consume_remote_fuel ( int  amount)

Consume fuel used by remote powered bionic, return amount of request unfulfilled (0 if totally successful).

Definition at line 1412 of file bionics.cpp.

1413{
1414 int unconsumed_amount = amount;
1415 const std::vector<item *> cables = items_with( []( const item & it ) {
1416 return it.active && it.has_flag( flag_CABLE_SPOOL );
1417 } );
1418
1419 map &here = get_map();
1420 for( const item *cable : cables ) {
1421 const cata::optional<tripoint> target = cable->get_cable_target( this, pos() );
1422 if( target ) {
1423 const optional_vpart_position vp = here.veh_at( *target );
1424 if( !vp ) {
1425 continue;
1426 }
1427 unconsumed_amount = vp->vehicle().discharge_battery( amount );
1428 }
1429 }
1430
1431 if( unconsumed_amount > 0 ) {
1432 static const item_filter used_ups = [&]( const item & itm ) {
1433 return itm.get_var( "cable" ) == "plugged_in";
1434 };
1435 if( has_charges( itype_UPS_off, unconsumed_amount, used_ups ) ) {
1436 use_charges( itype_UPS_off, unconsumed_amount, used_ups );
1437 unconsumed_amount -= 1;
1438 } else if( has_charges( itype_adv_UPS_off, unconsumed_amount, used_ups ) ) {
1439 use_charges( itype_adv_UPS_off, roll_remainder( unconsumed_amount * 0.6 ), used_ups );
1440 unconsumed_amount -= 1;
1441 }
1442 }
1443
1444 return unconsumed_amount;
1445}
static const itype_id itype_adv_UPS_off("adv_UPS_off")
static const itype_id itype_UPS_off("UPS_off")
std::function< bool(const item &)> item_filter
Definition: game.h:119

References item::active, flag_CABLE_SPOOL(), get_map(), has_charges(), item::has_flag(), visitable< Character >::items_with(), itype_adv_UPS_off, itype_UPS_off, pos(), roll_remainder(), and use_charges().

Referenced by burn_fuel().

◆ cough()

void Character::cough ( bool  harmful = false,
int  loudness = 4 
)

Definition at line 7661 of file character.cpp.

7662{
7664 return;
7665 }
7666
7667 if( harmful ) {
7668 const int stam = get_stamina();
7669 const int malus = get_stamina_max() * 0.05; // 5% max stamina
7670 mod_stamina( -malus );
7671 if( stam < malus && x_in_y( malus - stam, malus ) && one_in( 6 ) ) {
7672 apply_damage( nullptr, bodypart_id( "torso" ), 1 );
7673 }
7674 }
7675
7676 if( !is_npc() ) {
7677 add_msg( m_bad, _( "You cough heavily." ) );
7678 }
7679 sounds::sound( pos(), loudness, sounds::sound_t::speech, _( "a hacking cough." ), false, "misc",
7680 "cough" );
7681
7682 moves -= 80;
7683
7684 add_effect( effect_recently_coughed, 5_minutes );
7685}
static const efftype_id effect_cough_suppress("cough_suppress")
static const efftype_id effect_recently_coughed("recently_coughed")

References _, Creature::add_effect(), add_msg(), apply_damage(), effect_cough_suppress, effect_recently_coughed, get_stamina(), get_stamina_max(), Creature::has_effect(), Creature::is_npc(), m_bad, mod_stamina(), Creature::moves, one_in(), pos(), sounds::sound(), sounds::speech, and x_in_y().

Referenced by eff_fun_fungus(), and player::process_one_effect().

◆ covered_with_flag()

bool Character::covered_with_flag ( const std::string &  flag,
const body_part_set parts 
) const

Definition at line 8986 of file character.cpp.

8987{
8988 if( parts.none() ) {
8989 return true;
8990 }
8991
8992 body_part_set to_cover( parts );
8993
8994 for( const auto &elem : worn ) {
8995 if( !elem.has_flag( flag ) ) {
8996 continue;
8997 }
8998
8999 to_cover &= ~elem.get_covered_body_parts();
9000
9001 if( to_cover.none() ) {
9002 return true; // Allows early exit.
9003 }
9004 }
9005
9006 return to_cover.none();
9007}
bool none() const
Definition: bodypart.h:249

References body_part_set::none(), and worn.

Referenced by is_waterproof().

◆ crafting_inventory() [1/2]

◆ crafting_inventory() [2/2]

const inventory & Character::crafting_inventory ( const tripoint src_pos = tripoint_zero,
int  radius = PICKUP_RANGE,
bool  clear_path = true 
)

Definition at line 553 of file crafting.cpp.

555{
556 tripoint inv_pos = src_pos;
557 if( src_pos == tripoint_zero ) {
558 inv_pos = pos();
559 }
560 if( cached_moves == moves
562 && cached_position == inv_pos ) {
564 }
565 cached_crafting_inventory.form_from_map( inv_pos, radius, this, false, clear_path );
569 for( const bionic &bio : *my_bionics ) {
570 const bionic_data &bio_data = bio.info();
571 if( ( !bio_data.activated || bio.powered ) &&
572 !bio_data.fake_item.is_empty() ) {
573 cached_crafting_inventory += item( bio.info().fake_item,
575 }
576 }
577 if( has_trait( trait_BURROW ) ) {
580 }
581
584 cached_position = inv_pos;
585 // cache the qualities of the items in cached_crafting_inventory
588}
tripoint cached_position
Definition: character.h:2202
int cached_moves
Definition: character.h:2201
inventory cached_crafting_inventory
Definition: character.h:2203
void form_from_map(const tripoint &origin, int range, const Character *pl=nullptr, bool assign_invlet=true, bool clear_path=true)
Definition: inventory.cpp:472
void update_quality_cache()
Definition: inventory.cpp:1114
static const trait_id trait_BURROW("BURROW")
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:49

References bionic_data::activated, cached_crafting_inventory, cached_moves, cached_position, cached_time, bionic_data::fake_item, inventory::form_from_map(), get_power_level(), has_trait(), inv, string_id< T >::is_empty(), Creature::moves, my_bionics, pos(), units::to_kilojoule(), trait_BURROW, tripoint_zero, calendar::turn, inventory::update_quality_cache(), weapon, and worn.

◆ crit_chance()

double Character::crit_chance ( float  roll_hit,
float  target_dodge,
const item weap 
) const

Returns the chance to critical given a hit roll and target's dodge roll.

Unarmed increases critical chance with UNARMED_WEAPON Dexterity increases chance for critical hits Perception increases chance for critical hits Bashing increases critical chance with bashing weapons Cutting increases critical chance with cutting weapons Stabbing increases critical chance with piercing weapons Unarmed increases critical chance with unarmed weapons Melee slightly increases critical chance with any item

Definition at line 741 of file melee.cpp.

742{
743 // Weapon to-hit roll
744 double weapon_crit_chance = 0.5;
745 if( weap.is_unarmed_weapon() ) {
746 // Unarmed attack: 1/2 of unarmed skill is to-hit
747 /** @EFFECT_UNARMED increases critical chance with UNARMED_WEAPON */
748 weapon_crit_chance = 0.5 + 0.05 * get_skill_level( skill_unarmed );
749 }
750
751 if( weap.type->m_to_hit > 0 ) {
752 weapon_crit_chance = std::max( weapon_crit_chance, 0.5 + 0.1 * weap.type->m_to_hit );
753 } else if( weap.type->m_to_hit < 0 ) {
754 weapon_crit_chance += 0.1 * weap.type->m_to_hit;
755 }
756 weapon_crit_chance = limit_probability( weapon_crit_chance );
757
758 // Dexterity and perception
759 /** @EFFECT_DEX increases chance for critical hits */
760
761 /** @EFFECT_PER increases chance for critical hits */
762 const double stat_crit_chance = limit_probability( 0.25 + 0.01 * dex_cur + ( 0.02 * per_cur ) );
763
764 /** @EFFECT_BASHING increases critical chance with bashing weapons */
765 /** @EFFECT_CUTTING increases critical chance with cutting weapons */
766 /** @EFFECT_STABBING increases critical chance with piercing weapons */
767 /** @EFFECT_UNARMED increases critical chance with unarmed weapons */
768 int sk = get_skill_level( weap.melee_skill() );
769 if( has_active_bionic( bio_cqb ) ) {
770 sk = std::max( sk, BIO_CQB_LEVEL );
771 }
772
773 /** @EFFECT_MELEE slightly increases critical chance with any item */
774 sk += get_skill_level( skill_melee ) / 2.5;
775
776 const double skill_crit_chance = limit_probability( 0.25 + sk * 0.025 );
777
778 // Examples (survivor stats/chances of each critical):
779 // Fresh (skill-less) 8/8/8/8, unarmed:
780 // 50%, 49%, 25%; ~1/16 guaranteed critical + ~1/8 if roll>dodge*1.5
781 // Expert (skills 10) 10/10/10/10, unarmed:
782 // 100%, 55%, 60%; ~1/3 guaranteed critical + ~4/10 if roll>dodge*1.5
783 // Godlike with combat CBM 20/20/20/20, pipe (+1 accuracy):
784 // 60%, 100%, 42%; ~1/4 guaranteed critical + ~3/8 if roll>dodge*1.5
785
786 // Note: the formulas below are only valid if none of the 3 critical chance values go above 1.0
787 // It is therefore important to limit them to between 0.0 and 1.0
788
789 // Chance to get all 3 criticals (a guaranteed critical regardless of hit/dodge)
790 const double chance_triple = weapon_crit_chance * stat_crit_chance * skill_crit_chance;
791 // Only check double critical (one that requires hit/dodge comparison) if we have good
792 // hit vs dodge
793 if( roll_hit > target_dodge * 3 / 2 ) {
794 const double chance_double = 0.5 * (
795 weapon_crit_chance * stat_crit_chance +
796 stat_crit_chance * skill_crit_chance +
797 weapon_crit_chance * skill_crit_chance -
798 ( 3 * chance_triple ) );
799 // Because chance_double already removed the triples with -( 3 * chance_triple ),
800 // chance_triple and chance_double are mutually exclusive probabilities and can just
801 // be added together.
803 melee::melee_stats.double_crit_chance += chance_double + chance_triple;
804 return chance_triple + chance_double;
805 }
807 melee::melee_stats.crit_chance += chance_triple;
808 return chance_triple;
809}
bool is_unarmed_weapon() const
Definition: item.cpp:737
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7041
double limit_probability(double unbounded_probability)
Limits a probability to be between 0.0 and 1.0.
Definition: melee.cpp:736
melee_statistic_data melee_stats
Definition: melee.cpp:2433
int m_to_hit
Definition: itype.h:998
double crit_chance
Definition: melee.h:15
int double_crit_count
Definition: melee.h:11
double double_crit_chance
Definition: melee.h:14

References bio_cqb, BIO_CQB_LEVEL, melee_statistic_data::crit_chance, melee_statistic_data::crit_count, dex_cur, melee_statistic_data::double_crit_chance, melee_statistic_data::double_crit_count, get_skill_level(), has_active_bionic(), item::is_unarmed_weapon(), limit_probability(), itype::m_to_hit, item::melee_skill(), melee::melee_stats, per_cur, skill_melee, skill_unarmed, and item::type.

Referenced by item::effective_dps(), and scored_crit().

◆ crossed_threshold()

bool Character::crossed_threshold ( ) const

Returns true if the player has crossed a mutation threshold Player can only cross one mutation threshold.

Definition at line 8730 of file character.cpp.

8731{
8732 for( const trait_id &mut : get_mutations() ) {
8733 if( mut->threshold ) {
8734 return true;
8735 }
8736 }
8737 return false;
8738}

References get_mutations(), and mutation_branch::threshold.

Referenced by character_display::disp_info(), draw_tip(), player::hardcoded_effects(), marloss_common(), modify_morale(), conditional_t< T >::set_has_trait_flag(), and test_crossing_threshold().

◆ deactivate_bionic()

bool Character::deactivate_bionic ( int  b,
bool  eff_only = false 
)

Handles bionic deactivation effects of the entered bionic, returns if anything deactivated.

Definition at line 1066 of file bionics.cpp.

1067{
1068 bionic &bio = ( *my_bionics )[b];
1069
1070 if( bio.incapacitated_time > 0_turns ) {
1071 add_msg( m_info, _( "Your %s is shorting out and can't be deactivated." ),
1072 bio.info().name );
1073 return false;
1074 }
1075
1076 if( bio.info().is_remote_fueled ) {
1078 }
1079
1080 // Just do the effect, no stat changing or messages
1081 if( !eff_only ) {
1082 if( !bio.powered ) {
1083 // It's already off!
1084 return false;
1085 }
1086 if( !bio.info().has_flag( flag_BIONIC_TOGGLED ) ) {
1087 // It's a fire-and-forget bionic, we can't turn it off but have to wait for
1088 //it to run out of charge
1089 add_msg_if_player( m_info, _( "You can't deactivate your %s manually!" ),
1090 bio.info().name );
1091 return false;
1092 }
1093 if( get_power_level() < bio.info().power_deactivate ) {
1094 add_msg( m_info, _( "You don't have the power to deactivate your %s." ),
1095 bio.info().name );
1096 return false;
1097 }
1098
1099 //We can actually deactivate now, do deactivation-y things
1101 bio.powered = false;
1102 add_msg_if_player( m_neutral, _( "You deactivate your %s." ), bio.info().name );
1103 }
1104
1105 // Deactivation effects go here
1106 if( bio.info().has_flag( flag_BIONIC_WEAPON ) ) {
1107 if( weapon.typeId() == bio.info().fake_item ) {
1108 add_msg_if_player( _( "You withdraw your %s." ), weapon.tname() );
1109 if( g->u.sees( pos() ) ) {
1110 add_msg_if_npc( m_info, _( "<npcname> withdraws %s %s." ), disp_name( true ),
1111 weapon.tname() );
1112 }
1113 bio.ammo_loaded =
1114 weapon.ammo_data() != nullptr ? weapon.ammo_data()->get_id() : itype_id::NULL_ID();
1115 bio.ammo_count = static_cast<unsigned int>( weapon.ammo_remaining() );
1116 weapon = item();
1118 }
1119 } else if( bio.id == bio_cqb ) {
1120 martial_arts_data->selected_style_check();
1121 } else if( bio.id == bio_remote ) {
1122 if( g->remoteveh() != nullptr && !has_active_item( itype_remotevehcontrol ) ) {
1123 g->setremoteveh( nullptr );
1124 } else if( !get_value( "remote_controlling" ).empty() &&
1126 set_value( "remote_controlling", "" );
1127 }
1128 } else if( bio.id == bio_tools ) {
1130 } else if( bio.id == bio_ads ) {
1132 bio.energy_stored = 0_kJ;
1133 }
1134
1135 // Recalculate stats (strength, mods from pain etc.) that could have been affected
1137 reset();
1138 if( !bio.id->enchantments.empty() ) {
1140 }
1141
1142 // Also reset crafting inventory cache if this bionic spawned a fake item
1143 if( !bio.info().fake_item.is_empty() ) {
1145 }
1146
1147 // Compatibility with old saves without the toolset hammerspace
1148 if( !eff_only && bio.id == bio_tools && !has_bionic( bionic_TOOLS_EXTEND ) ) {
1149 // E X T E N D T O O L S
1151 }
1152
1153 return true;
1154}
static const bionic_id bio_ads("bio_ads")
static const itype_id itype_remotevehcontrol("remotevehcontrol")
static const bionic_id bionic_TOOLS_EXTEND("bio_tools_extend")
static const itype_id itype_radiocontrol("radiocontrol")
bool has_active_item(const itype_id &id) const
Whether the player carries an active item of the given item type.
Definition: character.cpp:2564
void reset_remote_fuel()
Definition: bionics.cpp:1447
virtual void add_msg_if_npc(const std::string &) const
Definition: creature.h:635
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7370
static const string_id< itype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
units::energy power_deactivate
Power cost on deactivation.
Definition: bionics.h:39

References _, add_bionic(), add_msg(), Creature::add_msg_if_npc(), Creature::add_msg_if_player(), bionic::ammo_count, item::ammo_data(), bionic::ammo_loaded, item::ammo_remaining(), b, bio_ads, bio_cqb, bio_remote, bio_tools, bionic_TOOLS_EXTEND, disp_name(), bionic_data::enchantments, bionic::energy_stored, bionic_data::fake_item, flag_BIONIC_TOGGLED, flag_BIONIC_WEAPON, g, itype::get_id(), get_power_level(), Creature::get_value(), has_active_item(), has_bionic(), bionic_data::has_flag(), bionic::id, bionic::incapacitated_time, bionic::info(), invalidate_crafting_inventory(), string_id< T >::is_empty(), bionic_data::is_remote_fueled, itype_radiocontrol, itype_remotevehcontrol, m_info, m_neutral, martial_arts_data, mod_power_level(), bionic_data::name, string_id< itype >::NULL_ID(), pos(), bionic_data::power_deactivate, bionic::powered, recalculate_enchantment_cache(), reset(), reset_encumbrance(), reset_remote_fuel(), Creature::set_value(), item::tname(), item::typeId(), and weapon.

Referenced by absorb_hit(), burn_fuel(), npc::deactivate_bionic_by_id(), player::power_bionics(), process_bionic(), and uninstall_bionic().

◆ deactivate_mutation()

void Character::deactivate_mutation ( const trait_id mut)

Definition at line 610 of file mutation.cpp.

611{
612 my_mutations[mut].powered = false;
613
614 // Handle stat changes from deactivation
615 apply_mods( mut, false );
617 const mutation_branch &mdata = mut.obj();
618 if( mdata.transform ) {
619 const cata::value_ptr<mut_transform> trans = mdata.transform;
620 mod_moves( -trans->moves );
621 switch_mutations( mut, trans->target, trans->active );
622 }
623
624 if( !mut->enchantments.empty() ) {
626 }
627}
void apply_mods(const trait_id &mut, bool add_remove)
Applies stat mods to character.
Definition: mutation.cpp:206
std::vector< enchantment_id > enchantments
mutation enchantments
Definition: mutation.h:234

References apply_mods(), mutation_branch::enchantments, Creature::mod_moves(), my_mutations, string_id< T >::obj(), recalc_sight_limits(), recalculate_enchantment_cache(), switch_mutations(), and mutation_branch::transform.

Referenced by player::power_mutations(), and player::power_mutations_ui().

◆ deal_damage()

dealt_damage_instance Character::deal_damage ( Creature source,
bodypart_id  bp,
const damage_instance d 
)
overridevirtual

Calls Creature::deal_damage and handles damaged effects (waking up, etc.)

Dexterity increases chance to avoid being grabbed

Reimplemented from Creature.

Definition at line 8473 of file character.cpp.

8475{
8476 if( has_trait( trait_DEBUG_NODMG ) ) {
8477 return dealt_damage_instance();
8478 }
8479
8480 const body_part bp_token = bp->token;
8481 if( bp_token == num_bp ) {
8482 debugmsg( "Wacky bodypart hit!" );
8483 return dealt_damage_instance();
8484 }
8485
8486 //damage applied here
8487 dealt_damage_instance dealt_dams = Creature::deal_damage( source, bp, d );
8488 //block reduction should be by applied this point
8489 int dam = dealt_dams.total_damage();
8490
8491 // TODO: Pre or post blit hit tile onto "this"'s location here
8492 if( dam > 0 && g->u.sees( pos() ) ) {
8493 g->draw_hit_player( *this, dam );
8494
8495 if( is_player() && source ) {
8496 //monster hits player melee
8497 SCT.add( point( posx(), posy() ),
8498 direction_from( point_zero, point( posx() - source->posx(), posy() - source->posy() ) ),
8499 get_hp_bar( dam, get_hp_max( bp ) ).first, m_bad, body_part_name( bp ), m_neutral );
8500 }
8501 }
8502
8503 // handle snake artifacts
8504 if( has_artifact_with( AEP_SNAKES ) && dam >= 6 ) {
8505 const int snakes = dam / 6;
8506 int spawned = 0;
8507 for( int i = 0; i < snakes; i++ ) {
8508 if( monster *const snake = g->place_critter_around( mon_shadow_snake, pos(), 1 ) ) {
8509 snake->friendly = -1;
8510 spawned++;
8511 }
8512 }
8513 if( spawned == 1 ) {
8514 add_msg( m_warning, _( "A snake sprouts from your body!" ) );
8515 } else if( spawned >= 2 ) {
8516 add_msg( m_warning, _( "Some snakes sprout from your body!" ) );
8517 }
8518 }
8519
8520 // And slimespawners too
8521 if( ( has_trait( trait_SLIMESPAWNER ) ) && ( dam >= 10 ) && one_in( 20 - dam ) ) {
8522 if( monster *const slime = g->place_critter_around( mon_player_blob, pos(), 1 ) ) {
8523 slime->friendly = -1;
8524 add_msg_if_player( m_warning, _( "Slime is torn from you, and moves on its own!" ) );
8525 }
8526 }
8527
8528 //Acid blood effects.
8529 bool u_see = g->u.sees( *this );
8530 int cut_dam = dealt_dams.type_damage( DT_CUT );
8531 if( source && has_trait( trait_ACIDBLOOD ) && !one_in( 3 ) &&
8532 ( dam >= 4 || cut_dam > 0 ) && ( rl_dist( g->u.pos(), source->pos() ) <= 1 ) ) {
8533 if( is_player() ) {
8534 add_msg( m_good, _( "Your acidic blood splashes %s in mid-attack!" ),
8535 source->disp_name() );
8536 } else if( u_see ) {
8537 add_msg( _( "%1$s's acidic blood splashes on %2$s in mid-attack!" ),
8538 disp_name(), source->disp_name() );
8539 }
8540 damage_instance acidblood_damage;
8541 acidblood_damage.add_damage( DT_ACID, rng( 4, 16 ) );
8542 if( !one_in( 4 ) ) {
8543 source->deal_damage( this, bodypart_id( "arm_l" ), acidblood_damage );
8544 source->deal_damage( this, bodypart_id( "arm_r" ), acidblood_damage );
8545 } else {
8546 source->deal_damage( this, bodypart_id( "torso" ), acidblood_damage );
8547 source->deal_damage( this, bodypart_id( "head" ), acidblood_damage );
8548 }
8549 }
8550
8551 int recoil_mul = 100;
8552
8553 if( bp == bodypart_id( "eyes" ) ) {
8554 if( dam > 5 || cut_dam > 0 ) {
8555 const time_duration minblind = std::max( 1_turns, 1_turns * ( dam + cut_dam ) / 10 );
8556 const time_duration maxblind = std::min( 5_turns, 1_turns * ( dam + cut_dam ) / 4 );
8557 add_effect( effect_blind, rng( minblind, maxblind ) );
8558 }
8559 } else if( bp == bodypart_id( "hand_l" ) || bp == bodypart_id( "arm_l" ) ||
8560 bp == bodypart_id( "hand_r" ) || bp == bodypart_id( "arm_r" ) ) {
8561 recoil_mul = 200;
8562 } else if( bp == bodypart_id( "num_bp" ) ) {
8563 debugmsg( "Wacky body part hit!" );
8564 }
8565
8566
8567
8568 // TODO: Scale with damage in a way that makes sense for power armors, plate armor and naked skin.
8569 recoil += recoil_mul * weapon.volume() / 250_ml;
8570 recoil = std::min( MAX_RECOIL, recoil );
8571 //looks like this should be based off of dealt damages, not d as d has no damage reduction applied.
8572 // Skip all this if the damage isn't from a creature. e.g. an explosion.
8573 if( source != nullptr ) {
8574 if( source->has_flag( MF_GRABS ) && !source->is_hallucination() &&
8575 !source->has_effect( effect_grabbing ) ) {
8576 /** @EFFECT_DEX increases chance to avoid being grabbed */
8577
8578 if( has_grab_break_tec() && ( rng( 0, get_dex() ) > rng( 0, 10 ) ) ) {
8579 if( has_effect( effect_grabbed ) ) {
8580 add_msg_if_player( m_warning, _( "The %s tries to grab you as well, but you bat it away!" ),
8581 source->disp_name() );
8582 } else {
8583 add_msg_player_or_npc( m_info, _( "The %s tries to grab you, but you break its grab!" ),
8584 _( "The %s tries to grab <npcname>, but they break its grab!" ),
8585 source->disp_name() );
8586 }
8587 } else {
8588 int prev_effect = get_effect_int( effect_grabbed );
8589 add_effect( effect_grabbed, 2_turns, bp_torso, prev_effect + 2 );
8590 source->add_effect( effect_grabbing, 2_turns );
8591 add_msg_player_or_npc( m_bad, _( "You are grabbed by %s!" ), _( "<npcname> is grabbed by %s!" ),
8592 source->disp_name() );
8593 }
8594 }
8595 }
8596
8597 if( get_option<bool>( "FILTHY_WOUNDS" ) ) {
8598 int sum_cover = 0;
8599 for( const item &i : worn ) {
8600 if( i.covers( bp->token ) && i.is_filthy() ) {
8601 sum_cover += i.get_coverage();
8602 }
8603 }
8604
8605 // Chance of infection is damage (with cut and stab x4) * sum of coverage on affected body part, in percent.
8606 // i.e. if the body part has a sum of 100 coverage from filthy clothing,
8607 // each point of damage has a 1% change of causing infection.
8608 if( sum_cover > 0 ) {
8609 const int cut_type_dam = dealt_dams.type_damage( DT_CUT ) + dealt_dams.type_damage( DT_STAB );
8610 const int combined_dam = dealt_dams.type_damage( DT_BASH ) + ( cut_type_dam * 4 );
8611 const int infection_chance = ( combined_dam * sum_cover ) / 100;
8612 if( x_in_y( infection_chance, 100 ) ) {
8613 if( has_effect( effect_bite, bp->token ) ) {
8614 add_effect( effect_bite, 40_minutes, bp->token );
8615 } else if( has_effect( effect_infected, bp->token ) ) {
8616 add_effect( effect_infected, 25_minutes, bp->token );
8617 } else {
8618 add_effect( effect_bite, 1_turns, bp->token );
8619 }
8620 add_msg_if_player( _( "Filth from your clothing has implanted deep in the wound." ) );
8621 }
8622 }
8623 }
8624
8625 on_hurt( source );
8626 return dealt_dams;
8627}
static const efftype_id effect_blind("blind")
static const trait_id trait_SLIMESPAWNER("SLIMESPAWNER")
static const mtype_id mon_player_blob("mon_player_blob")
static const efftype_id effect_grabbing("grabbing")
static const mtype_id mon_shadow_snake("mon_shadow_snake")
static const efftype_id effect_grabbed("grabbed")
bool has_grab_break_tec() const override
Returns true if the player has a grab breaking technique available.
virtual int posy() const =0
virtual std::string disp_name(bool possessive=false, bool capitalize_first=false) const =0
virtual const tripoint & pos() const =0
virtual dealt_damage_instance deal_damage(Creature *source, bodypart_id bp, const damage_instance &dam)
Deals the damage via an attack.
Definition: creature.cpp:879
virtual bool has_flag(const m_flag) const
Definition: creature.h:482
virtual int get_hp_max() const
Definition: creature.cpp:1669
virtual int posx() const =0
direction direction_from(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:540
@ AEP_SNAKES
Definition: enums.h:109
@ MF_GRABS
Definition: mtype.h:76
bool snake(const tripoint &p, Creature *c, item *i)
Definition: trapfunc.cpp:1428
static constexpr point point_zero
Definition: point.h:274
void add_damage(damage_type dt, float amt, float arpen=0.0f, float arpen_mult=1.0f, float dmg_mult=1.0f)
Adds damage to the instance.
Definition: damage.cpp:41
int type_damage(damage_type dt) const
Definition: damage.cpp:172
int total_damage() const
Definition: damage.cpp:180

References _, scrollingcombattext::add(), damage_instance::add_damage(), Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), AEP_SNAKES, body_part_name(), bp_torso, Creature::deal_damage(), debugmsg, direction_from(), Creature::disp_name(), disp_name(), DT_ACID, DT_BASH, DT_CUT, DT_STAB, effect_bite, effect_blind, effect_grabbed, effect_grabbing, effect_infected, g, get_dex(), Creature::get_effect_int(), get_hp_bar(), Creature::get_hp_max(), has_artifact_with(), Creature::has_effect(), Creature::has_flag(), has_grab_break_tec(), has_trait(), Creature::is_hallucination(), Creature::is_player(), m_bad, m_good, m_info, m_neutral, m_warning, MAX_RECOIL, MF_GRABS, mon_player_blob, mon_shadow_snake, num_bp, on_hurt(), one_in(), point_zero, Creature::pos(), pos(), Creature::posx(), posx(), Creature::posy(), posy(), recoil, rl_dist(), rng(), SCT, trapfunc::snake(), dealt_damage_instance::total_damage(), trait_ACIDBLOOD, trait_DEBUG_NODMG, trait_SLIMESPAWNER, dealt_damage_instance::type_damage(), item::volume(), weapon, worn, and x_in_y().

Referenced by mattack::bio_op_impale(), mattack::bio_op_takedown(), map::burn_body_part(), map::crush(), trapfunc::dissector(), explosion_handler::do_blast(), map::drop_furniture(), eff_fun_onfire(), forced_dismount(), trapfunc::goo(), hitall(), player::impact(), player::knock_back_to(), game::knockback(), trapfunc::lava(), melee_special_effects(), petfood(), trapfunc::pit(), trapfunc::pit_glass(), trapfunc::pit_spikes(), game::place_player(), map::player_in_field(), smash(), trapfunc::snare_heavy(), and mattack::thrown_by_judo().

◆ defer_move()

bool Character::defer_move ( const tripoint next)

Definition at line 10558 of file character.cpp.

10559{
10560 // next must be adjacent to current pos
10561 if( square_dist( next, pos() ) != 1 ) {
10562 return false;
10563 }
10564 // next must be adjacent to subsequent move in any preexisting automove route
10565 if( has_destination() && square_dist( auto_move_route.front(), next ) != 1 ) {
10566 return false;
10567 }
10568 auto_move_route.insert( auto_move_route.begin(), next );
10570 return true;
10571}
bool has_destination() const
int square_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:505

References auto_move_route, has_destination(), next_expected_position, pos(), and square_dist().

Referenced by avatar_action::move().

◆ did_hit()

void Character::did_hit ( Creature target)

Definition at line 8406 of file character.cpp.

8407{
8408 enchantment_cache->cast_hit_you( *this, target );
8409}

References enchantment_cache.

Referenced by melee_attack().

◆ die()

void Character::die ( Creature killer)
overridevirtual

Empty function.

Should always be overwritten by the appropriate player/NPC/monster version.

Implements Creature.

Reimplemented in npc.

Definition at line 3485 of file character.cpp.

3486{
3487 g->set_critter_died();
3488 set_killer( nkiller );
3490 if( has_effect( effect_lightsnare ) ) {
3493 }
3494 if( has_effect( effect_heavysnare ) ) {
3497 }
3498 if( has_effect( effect_beartrap ) ) {
3500 }
3502}
static const itype_id itype_string_36("string_36")
static const efftype_id effect_lightsnare("lightsnare")
static const itype_id itype_snare_trigger("snare_trigger")
static const itype_id itype_beartrap("beartrap")
static const efftype_id effect_beartrap("beartrap")
static const efftype_id effect_heavysnare("heavysnare")
static const itype_id itype_rope_6("rope_6")
void set_time_died(const time_point &time)
set the turn the turn the character died if not already done
Definition: character.h:1414
void set_killer(Creature *killer)
Definition: creature.cpp:1431
static void on_creature_death(Creature &poor_dead_dude)
various callbacks from events that may affect all missions
Definition: mission.cpp:132

References inventory::add_item(), effect_beartrap, effect_heavysnare, effect_lightsnare, g, Creature::has_effect(), inv, itype_beartrap, itype_rope_6, itype_snare_trigger, itype_string_36, mission::on_creature_death(), Creature::set_killer(), set_time_died(), calendar::start_of_cataclysm, and calendar::turn.

Referenced by debug_menu::debug(), and npc::die().

◆ dismount()

void Character::dismount ( )

Definition at line 1247 of file character.cpp.

1248{
1249 if( !is_mounted() ) {
1250 add_msg( m_debug, "dismount called when not riding" );
1251 return;
1252 }
1253 if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Dismount where?" ) ) ) {
1254 if( !g->is_empty( *pnt ) ) {
1255 add_msg( m_warning, _( "You cannot dismount there!" ) );
1256 return;
1257 }
1259 monster *critter = mounted_creature.get();
1260 critter->mounted_player_id = character_id();
1261 if( critter->has_flag( MF_RIDEABLE_MECH ) && !critter->type->mech_weapon.is_empty() &&
1262 weapon.typeId() == critter->type->mech_weapon ) {
1264 }
1265 if( is_avatar() && g->u.get_grab_type() != OBJECT_NONE ) {
1266 add_msg( m_warning, _( "You let go of the grabbed object." ) );
1267 g->u.grab( OBJECT_NONE );
1268 }
1269 critter->remove_effect( effect_ridden );
1270 critter->add_effect( effect_ai_waiting, 5_turns );
1271 mounted_creature = nullptr;
1272 critter->mounted_player = nullptr;
1273 setpos( *pnt );
1274 mod_moves( -100 );
1276 }
1277}
static const efftype_id effect_ai_waiting("ai_waiting")
static const efftype_id effect_riding("riding")
static const efftype_id effect_ridden("ridden")
void setpos(const tripoint &p) override
Definition: character.h:799
virtual void set_movement_mode(character_movemode mode)=0
virtual bool is_avatar() const
Definition: creature.h:95
void add_effect(const efftype_id &eff_id, const time_duration &dur, const bodypart_str_id &bp, int intensity=0, bool force=false, bool deferred=false) override
Performs any monster-specific modifications to the arguments before passing to Creature::add_effect()...
Definition: monster.cpp:1811
Character * mounted_player
Definition: monster.h:460
const mtype * type
Definition: monster.h:480
character_id mounted_player_id
Definition: monster.h:461
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:563
@ OBJECT_NONE
Definition: enums.h:187
itype_id mech_weapon
If this monster is a rideable mech with built-in weapons, this is the weapons id.
Definition: mtype.h:365

References _, monster::add_effect(), add_msg(), character_id, choose_adjacent(), CMM_WALK, effect_ai_waiting, effect_ridden, effect_riding, g, monster::has_flag(), Creature::is_avatar(), string_id< T >::is_empty(), is_mounted(), m_debug, m_warning, mtype::mech_weapon, MF_RIDEABLE_MECH, Creature::mod_moves(), mounted_creature, monster::mounted_player, monster::mounted_player_id, OBJECT_NONE, Creature::remove_effect(), visitable< Character >::remove_item(), set_movement_mode(), setpos(), monster::type, item::typeId(), and weapon.

Referenced by game::handle_action().

◆ disp_name()

std::string Character::disp_name ( bool  possessive = false,
bool  capitalize_first = false 
) const
overridevirtual

Returns either "you" or the player's name.

capitalize_first assumes that the character's name is already upper case and uses it only for possessive "your" and "you"

Implements Creature.

Definition at line 546 of file character.cpp.

547{
548 if( !possessive ) {
549 if( is_player() ) {
550 return capitalize_first ? _( "You" ) : _( "you" );
551 }
552 return name;
553 } else {
554 if( is_player() ) {
555 return capitalize_first ? _( "Your" ) : _( "your" );
556 }
557 return string_format( _( "%s's" ), name );
558 }
559}

References _, Creature::is_player(), name, and string_format().

Referenced by activity_on_turn_move_loot(), add_addiction(), iuse::artifact(), talk_function::assign_camp(), iexamine::autodoc(), best_installer(), bionics_install_failure(), activity_handlers::build_do_turn(), can_uninstall_bionic(), npc::character_danger(), game::chat(), check_and_recover_morale(), npc::check_or_use_weapon_cbm(), check_outbounds_activity(), complete_construction(), deactivate_bionic(), deal_damage(), faction_manager::display(), npc::do_npc_read(), npc::do_player_activity(), avatar::do_read(), npc::execute_action(), fetch_activity(), npc::finish_read(), talk_function::goto_location(), npc::handle_sound(), npc::heal_player(), npc::heal_self(), install_bionics(), game::list_missions(), npc::method_of_attack(), talk_function::morale_chat(), talk_function::morale_chat_activity(), npc::mutiny(), npc::npc_dismount(), game::npc_menu(), mattack::nurse_operate(), monster::nursebot_operate(), player::on_hit(), npc::on_load(), npc::pretend_fire(), npc::pretend_heal(), monster::print_info(), npc::reach_omt_destination(), avatar::read(), game_menus::inv::read(), requirements_map(), talk_effect_fun_t::set_consume_item(), npc::set_fac(), npc::set_known_to_u(), talk_function::start_camp(), player::uncanny_dodge(), uninstall_bionic(), trading_window::update_win(), musical_instrument_actor::use(), heal_actor::use_healing_item(), and npc::use_painkiller().

◆ dispose_item()

bool Character::dispose_item ( item_location &&  obj,
const std::string &  prompt = std::string() 
)
virtual

Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.

Parameters
objitem to dispose of
promptoptional message to display in any menu
Returns
whether the item was successfully disposed of

Reimplemented in npc.

Definition at line 7380 of file character.cpp.

7381{
7382 uilist menu;
7383 menu.text = prompt.empty() ? string_format( _( "Dispose of %s" ), obj->tname() ) : prompt;
7384
7385 using dispose_option = struct {
7386 std::string prompt;
7387 bool enabled;
7388 char invlet;
7389 int moves;
7390 std::function<bool()> action;
7391 };
7392
7393 std::vector<dispose_option> opts;
7394
7395 const bool bucket = obj->is_bucket_nonempty();
7396
7397 opts.emplace_back( dispose_option{
7398 bucket ? _( "Spill contents and store in inventory" ) : _( "Store in inventory" ),
7399 volume_carried() + obj->volume() <= volume_capacity(), '1',
7400 item_handling_cost( *obj ),
7401 [this, bucket, &obj] {
7402 if( bucket && !obj->spill_contents( *this ) )
7403 {
7404 return false;
7405 }
7406
7407 moves -= item_handling_cost( *obj );
7408 inv.add_item_keep_invlet( *obj );
7409 inv.unsort();
7410 obj.remove_item();
7411 return true;
7412 }
7413 } );
7414
7415 opts.emplace_back( dispose_option{
7416 _( "Drop item" ), true, '2', 0, [this, &obj] {
7418 obj.remove_item();
7419 return true;
7420 }
7421 } );
7422
7423 opts.emplace_back( dispose_option{
7424 bucket ? _( "Spill contents and wear item" ) : _( "Wear item" ),
7425 can_wear( *obj ).success(), '3', item_wear_cost( *obj ),
7426 [this, bucket, &obj] {
7427 if( bucket && !obj->spill_contents( *this ) )
7428 {
7429 return false;
7430 }
7431
7432 item it = *obj;
7433 obj.remove_item();
7434 return !!wear_item( it );
7435 }
7436 } );
7437
7438 for( auto &e : worn ) {
7439 if( e.can_holster( *obj ) ) {
7440 auto ptr = dynamic_cast<const holster_actor *>( e.type->get_use( "holster" )->get_actor_ptr() );
7441 opts.emplace_back( dispose_option{
7442 string_format( _( "Store in %s" ), e.tname() ), true, e.invlet,
7443 item_store_cost( *obj, e, false, ptr->draw_cost ),
7444 [this, ptr, &e, &obj] {
7445 return ptr->store( *this->as_player(), e, *obj );
7446 }
7447 } );
7448 }
7449 }
7450
7451 int w = utf8_width( menu.text, true ) + 4;
7452 for( const auto &e : opts ) {
7453 w = std::max( w, utf8_width( e.prompt, true ) + 4 );
7454 }
7455 for( auto &e : opts ) {
7456 e.prompt += std::string( w - utf8_width( e.prompt, true ), ' ' );
7457 }
7458
7459 menu.text.insert( 0, 2, ' ' ); // add space for UI hotkeys
7460 menu.text += std::string( w + 2 - utf8_width( menu.text, true ), ' ' );
7461 menu.text += _( " | Moves " );
7462
7463 for( const auto &e : opts ) {
7464 menu.addentry( -1, e.enabled, e.invlet, string_format( e.enabled ? "%s | %-7d" : "%s |",
7465 e.prompt, e.moves ) );
7466 }
7467
7468 menu.query();
7469 if( menu.ret >= 0 ) {
7470 return opts[menu.ret].action();
7471 }
7472 return false;
7473}
cata::optional< std::list< item >::iterator > wear_item(const item &to_wear, bool interactive=true)
Wear item; returns nullopt on fail, or pointer to newly worn item on success.
Definition: character.cpp:2184
int item_handling_cost(const item &it, bool penalties=true, int base_cost=INVENTORY_HANDLING_PENALTY) const
Calculate (but do not deduct) the number of moves required when handling (e.g.
Definition: character.cpp:7586
int item_wear_cost(const item &it) const
Calculate (but do not deduct) the number of moves required to wear an item.
Definition: character.cpp:7625
int item_store_cost(const item &it, const item &container, bool penalties=true, int base_cost=INVENTORY_HANDLING_PENALTY) const
Calculate (but do not deduct) the number of moves required when storing an item in a container.
Definition: character.cpp:7610
ret_val< bool > can_wear(const item &it, bool with_equip_change=false) const
Check character capable of wearing an item.
Definition: character.cpp:2945
Holster a weapon.
Definition: iuse_actor.h:843
void unsort()
Definition: inventory.cpp:226
void add_item_keep_invlet(item newit)
Definition: inventory.cpp:384
void remove_item()
Removes the selected item from the game.
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:6892
bool is_bucket_nonempty() const
Definition: item.cpp:6589
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.
@ prompt
Definition: pickup.h:30

References _, action, inventory::add_item_keep_invlet(), uilist::addentry(), Creature::as_player(), can_wear(), deliberate, enabled, inv, item_handling_cost(), item_store_cost(), item_wear_cost(), Creature::moves, pickup::prompt, ptr(), put_into_vehicle_or_drop(), uilist::query(), visitable< T >::remove_item(), uilist::ret, string_format(), uilist::text, inventory::unsort(), utf8_width(), volume_capacity(), volume_carried(), wear_item(), and worn.

Referenced by activate_bionic(), item::reload(), and player::unwield().

◆ do_damage_for_bionic_failure()

void Character::do_damage_for_bionic_failure ( int  min_damage,
int  max_damage 
)

Definition at line 2360 of file bionics.cpp.

2361{
2362 std::set<bodypart_id> bp_hurt;
2363 for( const bodypart_id &bp : get_all_body_parts() ) {
2364 if( has_effect( effect_under_op, bp->token ) ) {
2365 if( bp_hurt.count( bp->main_part ) > 0 ) {
2366 continue;
2367 }
2368 bp_hurt.emplace( bp->main_part );
2369 }
2370 }
2371
2372 if( bp_hurt.empty() ) {
2373 // If no bodypart associetd with bionic- just damage torso.
2374 // Special check for power storage - it does not belong to any body part.
2375 bp_hurt.emplace( bodypart_str_id( "torso" ) );
2376 }
2377
2378 for( const bodypart_id &bp : bp_hurt ) {
2379 int damage = rng( min_damage, max_damage );
2380 int hp = get_hp( bp );
2381 if( damage >= hp && ( bp == bodypart_str_id( "head" ) || bp == bodypart_str_id( "torso" ) ) ) {
2382 add_effect( effect_infected, 1_hours, bp->token );
2383 add_msg_player_or_npc( m_bad, _( "Your %s is infected." ), _( "<npcname>'s %s is infected." ),
2385 damage = hp * 0.8f;
2386 }
2387 apply_damage( this, bp, damage, true );
2388 if( damage > 15 )
2389 add_msg_player_or_npc( m_bad, _( "Your %s is severely damaged." ),
2390 _( "<npcname>'s %s is severely damaged." ),
2392 else
2393 add_msg_player_or_npc( m_bad, _( "Your %s is damaged." ), _( "<npcname>'s %s is damaged." ),
2395
2396 }
2397}
static const efftype_id effect_under_op("under_operation")
static const efftype_id effect_infected("infected")
std::string body_part_name_accusative(body_part bp, int number)
Returns the matching accusative name of the body_part token, i.e.
Definition: bodypart.cpp:329
virtual int get_hp() const
Definition: creature.cpp:1652

References _, Creature::add_effect(), Creature::add_msg_player_or_npc(), apply_damage(), body_part_name_accusative(), effect_infected, effect_under_op, Creature::get_all_body_parts(), Creature::get_hp(), Creature::has_effect(), m_bad, and rng().

Referenced by bionics_install_failure(), and bionics_uninstall_failure().

◆ do_skill_rust()

void Character::do_skill_rust ( )
protected

Definition at line 3535 of file character.cpp.

3536{
3537 const int rust_rate_tmp = rust_rate();
3538 static const std::string PRED2( "PRED2" );
3539 static const std::string PRED3( "PRED3" );
3540 static const std::string PRED4( "PRED4" );
3541 for( std::pair<const skill_id, SkillLevel> &pair : *_skills ) {
3542 const Skill &aSkill = *pair.first;
3543 SkillLevel &skill_level_obj = pair.second;
3544
3545 if( aSkill.is_combat_skill() &&
3546 ( ( has_trait_flag( PRED2 ) && calendar::once_every( 8_hours ) ) ||
3547 ( has_trait_flag( PRED3 ) && calendar::once_every( 4_hours ) ) ||
3548 ( has_trait_flag( PRED4 ) && calendar::once_every( 3_hours ) ) ) ) {
3549 // Their brain is optimized to remember this
3550 if( one_in( 13 ) ) {
3551 // They've already passed the roll to avoid rust at
3552 // this point, but print a message about it now and
3553 // then.
3554 //
3555 // 13 combat skills.
3556 // This means PRED2/PRED3/PRED4 think of hunting on
3557 // average every 8/4/3 hours, enough for immersion
3558 // without becoming an annoyance.
3559 //
3560 add_msg_if_player( _( "Your heart races as you recall your most recent hunt." ) );
3561 mod_stim( 1 );
3562 }
3563 continue;
3564 }
3565
3566 const bool charged_bio_mem = get_power_level() > 25_J && has_active_bionic( bio_memory );
3567 const int oldSkillLevel = skill_level_obj.level();
3568 if( skill_level_obj.rust( charged_bio_mem, rust_rate_tmp ) ) {
3570 _( "Your knowledge of %s begins to fade, but your memory banks retain it!" ), aSkill.name() );
3571 mod_power_level( -25_J );
3572 }
3573 const int newSkill = skill_level_obj.level();
3574 if( newSkill < oldSkillLevel ) {
3575 add_msg_if_player( m_bad, _( "Your skill in %s has reduced to %d!" ), aSkill.name(), newSkill );
3576 }
3577 }
3578}
pimpl< SkillLevelMap > _skills
Definition: character.h:2105
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:108
int rust_rate() const
Returns the player's skill rust rate.
Definition: character.cpp:3403
void mod_stim(int mod)
Definition: character.cpp:7185
int level() const
Definition: skill.h:125
bool rust(bool charged_bio_mem, int character_rate)
Definition: skill.cpp:256
Definition: skill.h:33
std::string name() const
Definition: skill.h:68
bool is_combat_skill() const
Definition: skill.cpp:198

References _, _skills, Creature::add_msg_if_player(), bio_memory, get_power_level(), has_active_bionic(), has_trait_flag(), Skill::is_combat_skill(), SkillLevel::level(), m_bad, m_warning, mod_power_level(), mod_stim(), Skill::name(), calendar::once_every(), one_in(), SkillLevel::rust(), and rust_rate().

Referenced by update_body().

◆ drench()

void Character::drench ( int  saturation,
const body_part_set flags,
bool  ignore_waterproof 
)

Drenches the player with water, saturation is the percent gotten wet.

Definition at line 1755 of file suffer.cpp.

1756{
1757 if( saturation < 1 ) {
1758 return;
1759 }
1760
1761 // OK, water gets in your AEP suit or whatever. It wasn't built to keep you dry.
1763 ( !ignore_waterproof && is_waterproof( flags ) ) ) {
1764 return;
1765 }
1766
1767 // Make the body wet
1768 for( const body_part bp : all_body_parts ) {
1769 // Different body parts have different size, they can only store so much water
1770 int bp_wetness_max = 0;
1771 if( flags.test( bp ) ) {
1772 bp_wetness_max = drench_capacity[bp];
1773 }
1774
1775 if( bp_wetness_max == 0 ) {
1776 continue;
1777 }
1778 // Different sources will only make the bodypart wet to a limit
1779 int source_wet_max = saturation * bp_wetness_max * 2 / 100;
1780 int wetness_increment = ignore_waterproof ? 100 : 2;
1781 // Respect maximums
1782 const int wetness_max = std::min( source_wet_max, bp_wetness_max );
1783 if( body_wetness[bp] < wetness_max ) {
1784 body_wetness[bp] = std::min( wetness_max, body_wetness[bp] + wetness_increment );
1785 }
1786 }
1787
1790 get_value( "waterproof_scent" ).empty() ) {
1791 add_msg_if_player( m_info, _( "The water wash away the scent." ) );
1792 restore_scent();
1793 }
1794
1795 if( is_weak_to_water() ) {
1796 add_msg_if_player( m_bad, _( "You feel the water burning your skin." ) );
1797 }
1798
1799 // Remove onfire effect
1800 if( saturation > 10 || x_in_y( saturation, 10 ) ) {
1802 }
1803}
bool is_waterproof(const body_part_set &parts) const
Definition: character.cpp:9009
bool is_weak_to_water() const
Definition: mutation.cpp:414
void restore_scent()
restore scent after masked_scent effect run out or is removed by water
Definition: character.cpp:8778
static const trait_id trait_DEBUG_NOTEMP("DEBUG_NOTEMP")
static const efftype_id effect_masked_scent("masked_scent")
static const trait_id trait_SHELL2("SHELL2")
static const efftype_id effect_onfire("onfire")

References _, Creature::add_msg_if_player(), all_body_parts, body_wetness, bp_torso, drench_capacity, effect_masked_scent, effect_onfire, Creature::get_value(), has_active_mutation(), Creature::has_effect(), has_trait(), is_waterproof(), is_weak_to_water(), m_bad, m_info, Creature::remove_effect(), restore_scent(), body_part_set::test(), trait_DEBUG_NOTEMP, trait_SHELL2, and x_in_y().

Referenced by player::pause(), game::place_player(), and avatar_action::swim().

◆ drench_mut_calc()

void Character::drench_mut_calc ( )

Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats)

Definition at line 7960 of file character.cpp.

7961{
7962 for( const body_part bp : all_body_parts ) {
7963 int ignored = 0;
7964 int neutral = 0;
7965 int good = 0;
7966
7967 for( const trait_id &iter : get_mutations() ) {
7968 const mutation_branch &mdata = iter.obj();
7969 const auto wp_iter = mdata.protection.find( bp );
7970 if( wp_iter != mdata.protection.end() ) {
7971 ignored += wp_iter->second.x;
7972 neutral += wp_iter->second.y;
7973 good += wp_iter->second.z;
7974 }
7975 }
7976
7977 mut_drench[bp][WT_GOOD] = good;
7979 mut_drench[bp][WT_IGNORED] = ignored;
7980 }
7981}
@ good
Item should display as green.
std::map< body_part, tripoint > protection
Definition: mutation.h:265

References all_body_parts, get_mutations(), good, mut_drench, neutral, mutation_branch::protection, WT_GOOD, WT_IGNORED, and WT_NEUTRAL.

Referenced by avatar::load(), mutate_towards(), remove_mutation(), and game::start_game().

◆ drop() [1/2]

void Character::drop ( const drop_locations what,
const tripoint target,
bool  stash = false 
)
virtual

Reimplemented in npc.

Definition at line 2530 of file character.cpp.

2532{
2533 if( what.empty() ) {
2534 return;
2535 }
2536
2537 if( rl_dist( pos(), target ) > 1 || !( stash || get_map().can_put_items( target ) ) ) {
2538 add_msg_player_or_npc( m_info, _( "You can't place items here!" ),
2539 _( "<npcname> can't place items here!" ) );
2540 return;
2541 }
2542
2543 if( stash ) {
2544 assign_activity( stash_activity_actor( *this, what, target - pos() ) );
2545 } else {
2546 assign_activity( drop_activity_actor( *this, what, false, target - pos() ) );
2547 }
2548}

References _, Creature::add_msg_player_or_npc(), assign_activity(), get_map(), m_info, pos(), and rl_dist().

◆ drop() [2/2]

void Character::drop ( item_location  loc,
const tripoint where 
)

Drops an item to the specified location.

Definition at line 2508 of file character.cpp.

2509{
2510 item &oThisItem = *loc;
2511 if( is_wielding( oThisItem ) ) {
2512 const auto ret = can_unwield( *loc );
2513
2514 if( !ret.success() ) {
2515 add_msg( m_info, "%s", ret.c_str() );
2516 return;
2517 }
2518 } else if( is_wearing( oThisItem ) ) {
2519 const auto ret = as_player()->can_takeoff( *loc );
2520
2521 if( !ret.success() ) {
2522 add_msg( m_info, "%s", ret.c_str() );
2523 return;
2524 }
2525 }
2526
2527 drop( { drop_location( loc, loc->count() ) }, where );
2528}
bool is_wielding(const item &target) const
Definition: character.cpp:3238
void drop(item_location loc, const tripoint &where)
Drops an item to the specified location.
Definition: character.cpp:2508
ret_val< bool > can_takeoff(const item &it, const std::list< item > *res=nullptr) const
Check player capable of taking off an item.
Definition: player.cpp:2848
iuse_location drop_location

References add_msg(), Creature::as_player(), player::can_takeoff(), can_unwield(), item::count(), drop(), is_wearing(), is_wielding(), m_info, and cata::hash64_detail::ret.

Referenced by game::drop(), npc::drop(), drop(), game::drop_in_direction(), harvest_common(), i_add_or_drop(), game::inventory_item_menu(), suffer_from_schizophrenia(), and player::takeoff().

◆ drop_invalid_inventory()

void Character::drop_invalid_inventory ( )

Definition at line 3201 of file character.cpp.

3202{
3203 bool dropped_liquid = false;
3204 for( const std::list<item> *stack : inv.const_slice() ) {
3205 const item &it = stack->front();
3206 if( it.made_of( LIQUID ) ) {
3207 dropped_liquid = true;
3208 get_map().add_item_or_charges( pos(), it );
3209 // must be last
3210 i_rem( &it );
3211 }
3212 }
3213 if( dropped_liquid ) {
3214 add_msg_if_player( m_bad, _( "Liquid from your inventory has leaked onto the ground." ) );
3215 }
3216
3217 if( volume_carried() > volume_capacity() ) {
3218 auto items_to_drop = inv.remove_randomly_by_volume( volume_carried() - volume_capacity() );
3220 }
3221}
std::list< item > remove_randomly_by_volume(const units::volume &volume)
Randomly select items until the volume quota is filled.
Definition: inventory.cpp:755
const_invslice const_slice() const
Definition: inventory.cpp:142
@ LIQUID
Definition: enums.h:175

References _, map::add_item_or_charges(), Creature::add_msg_if_player(), inventory::const_slice(), get_map(), i_rem(), inv, LIQUID, m_bad, item::made_of(), pos(), put_into_vehicle_or_drop(), inventory::remove_randomly_by_volume(), tumbling, volume_capacity(), and volume_carried().

Referenced by absorb_hit(), player_activity::do_turn(), npc::execute_action(), player::process_turn(), and npc_trading::trade().

◆ effective_dispersion()

int Character::effective_dispersion ( int  dispersion) const
Perception penalizes sight dispersion when low.

Definition at line 567 of file character.cpp.

568{
569 /** @EFFECT_PER penalizes sight dispersion when low. */
570 dispersion += ranged_per_mod();
571
572 dispersion += encumb( bp_eyes ) / 2;
573
574 return std::max( dispersion, 0 );
575}
virtual int ranged_per_mod() const
Definition: character.cpp:4151

References bp_eyes, encumb(), and ranged_per_mod().

Referenced by get_aim_types(), get_fastest_sight(), get_most_accurate_sight(), player::gun_value(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ empty_skills()

void Character::empty_skills ( )

Definition at line 2851 of file newcharacter.cpp.

2852{
2853 for( auto &sk : *_skills ) {
2854 sk.second.level( 0 );
2855 }
2856}

References _skills.

Referenced by reset_scenario().

◆ encumb()

◆ enforce_minimum_healing()

void Character::enforce_minimum_healing ( )

Definition at line 4626 of file character.cpp.

4627{
4628 for( const bodypart_id &bp : get_all_body_parts() ) {
4629 if( get_part_healed_total( bp ) <= 0 ) {
4630 heal( bp, 1 );
4631 }
4632 set_part_healed_total( bp, 0 );
4633 }
4634}
void heal(const bodypart_id &healed, int dam)
Heals a body_part for dam.
Definition: character.cpp:8654
void set_part_healed_total(const bodypart_id &id, int set)
Definition: creature.cpp:1585
int get_part_healed_total(const bodypart_id &id) const
Definition: creature.cpp:1570

References Creature::get_all_body_parts(), Creature::get_part_healed_total(), heal(), and Creature::set_part_healed_total().

Referenced by update_body().

◆ enough_power_for()

bool Character::enough_power_for ( const bionic_id bid) const

Definition at line 2022 of file character.cpp.

2023{
2024 return power_level >= bid->power_activate;
2025}
units::energy power_level
Definition: character.h:2176

References bionic_data::power_activate, and power_level.

Referenced by activate_bionic(), and iexamine::fireplace().

◆ enumerate_unmet_requirements()

std::string Character::enumerate_unmet_requirements ( const item it,
const item context = item() 
) const

Returns a string of missed requirements (both stats and skills)

Definition at line 3379 of file character.cpp.

3380{
3381 std::vector<std::string> unmet_reqs;
3382
3383 const auto check_req = [ &unmet_reqs ]( const std::string & name, int cur, int req ) {
3384 if( cur < req ) {
3385 unmet_reqs.push_back( string_format( "%s %d", name, req ) );
3386 }
3387 };
3388
3389 check_req( _( "strength" ), get_str(), it.get_min_str() );
3390 check_req( _( "dexterity" ), get_dex(), it.type->min_dex );
3391 check_req( _( "intelligence" ), get_int(), it.type->min_int );
3392 check_req( _( "perception" ), get_per(), it.type->min_per );
3393
3394 for( const auto &elem : it.type->min_skills ) {
3395 check_req( context.contextualize_skill( elem.first )->name(),
3396 get_skill_level( elem.first, context ),
3397 elem.second );
3398 }
3399
3400 return enumerate_as_string( unmet_reqs );
3401}
int get_min_str() const
Definition: item.cpp:9865
skill_id contextualize_skill(const skill_id &id) const
Puts the skill in context of the item.
Definition: item.cpp:9787
int min_dex
Definition: itype.h:938
int min_int
Definition: itype.h:939
int min_per
Definition: itype.h:940
std::map< skill_id, int > min_skills
Definition: itype.h:936

References _, item::contextualize_skill(), enumerate_as_string(), get_dex(), get_int(), item::get_min_str(), get_per(), get_skill_level(), get_str(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, name, Skill::name(), string_format(), and item::type.

Referenced by can_use(), and gunmod_inventory_preset::get_denial().

◆ env_surgery_bonus()

float Character::env_surgery_bonus ( int  radius)

Calculate skill bonus from tiles in radius.

Definition at line 2239 of file bionics.cpp.

2240{
2241 float bonus = 1.0;
2242 map &here = get_map();
2243 for( const tripoint &cell : here.points_in_radius( pos(), radius ) ) {
2244 if( here.furn( cell )->surgery_skill_multiplier ) {
2245 bonus = std::max( bonus, *here.furn( cell )->surgery_skill_multiplier );
2246 }
2247 }
2248 return bonus;
2249}
furn_id furn(const tripoint &p) const
Definition: map.cpp:1343
cata::optional< float > surgery_skill_multiplier
Definition: mapdata.h:511

References map::furn(), get_map(), map::points_in_radius(), pos(), and furn_t::surgery_skill_multiplier.

Referenced by bionics_adjusted_skill().

◆ exclusive_flag_coverage()

body_part_set Character::exclusive_flag_coverage ( const std::string &  flag) const

Bitset of all the body parts covered only with items with flag (or nothing)

Definition at line 4060 of file character.cpp.

4061{
4063
4064 for( const auto &elem : worn ) {
4065 if( !elem.has_flag( flag ) ) {
4066 // Unset the parts covered by this item
4067 ret &= ~elem.get_covered_body_parts();
4068 }
4069 }
4070
4071 return ret;
4072}
static body_part_set all()
Definition: bodypart.h:233

References body_part_set::all(), cata::hash64_detail::ret, and worn.

Referenced by apply_wetness_morale(), mut_cbm_encumb(), mutation_attacks(), player::reset_stats(), and swim_speed().

◆ expose_to_disease()

void Character::expose_to_disease ( diseasetype_id  dis_type)

Determine if character is susceptible to dis_type and if so apply the symptoms.

Definition at line 1627 of file character.cpp.

1628{
1629 const cata::optional<int> &healt_thresh = dis_type->health_threshold;
1630 if( healt_thresh && healt_thresh.value() < get_healthy() ) {
1631 return;
1632 }
1633 const std::set<body_part> &bps = dis_type->affected_bodyparts;
1634 if( !bps.empty() ) {
1635 for( const body_part &bp : bps ) {
1636 add_effect( dis_type->symptoms, rng( dis_type->min_duration, dis_type->max_duration ), bp,
1637 rng( dis_type->min_intensity, dis_type->max_intensity ) );
1638 }
1639 } else {
1640 add_effect( dis_type->symptoms, rng( dis_type->min_duration, dis_type->max_duration ), num_bp,
1641 rng( dis_type->min_intensity, dis_type->max_intensity ) );
1642 }
1643}
virtual int get_healthy() const
Getters for health values exclusive to characters.
Definition: character.cpp:4157
time_duration min_duration
Definition: disease.h:26
cata::optional< int > health_threshold
If not empty this sets the health threshold above which you're immune to the disease.
Definition: disease.h:33
int max_intensity
Definition: disease.h:29
efftype_id symptoms
effect applied by this disease
Definition: disease.h:35
std::set< body_part > affected_bodyparts
Affected body parts.
Definition: disease.h:31
int min_intensity
Definition: disease.h:28
time_duration max_duration
Definition: disease.h:27

References Creature::add_effect(), disease_type::affected_bodyparts, get_healthy(), disease_type::health_threshold, disease_type::max_duration, disease_type::max_intensity, disease_type::min_duration, disease_type::min_intensity, num_bp, rng(), disease_type::symptoms, and cata::optional< T >::value().

Referenced by player::eat().

◆ extended_description()

std::string Character::extended_description ( ) const
overridevirtual

Implements Creature.

Reimplemented in npc.

Definition at line 6624 of file character.cpp.

6625{
6626 std::string ss;
6627 if( is_player() ) {
6628 // <bad>This is me, <player_name>.</bad>
6629 ss += string_format( _( "This is you - %s." ), name );
6630 } else {
6631 ss += string_format( _( "This is %s, %s" ), name, male ? _( "male" ) : _( "female" ) );
6632 }
6633
6634 ss += "\n--\n";
6635
6636 const std::vector<bodypart_id> &bps = get_all_body_parts( true );
6637 // Find length of bp names, to align
6638 // accumulate looks weird here, any better function?
6639 int longest = std::accumulate( bps.begin(), bps.end(), 0,
6640 []( int m, bodypart_id bp ) {
6641 return std::max( m, utf8_width( body_part_name_as_heading( bp->token, 1 ) ) );
6642 } );
6643
6644 // This is a stripped-down version of the body_window function
6645 // This should be extracted into a separate function later on
6646 for( const bodypart_id &bp : bps ) {
6647 // Hide appendix from the player
6648 if( bp->id.str() == "num_bp" ) {
6649 continue;
6650 }
6651 const std::string &bp_heading = body_part_name_as_heading( bp->token, 1 );
6652
6653 const nc_color state_col = limb_color( bp, true, true, true );
6654 nc_color name_color = state_col;
6655 std::pair<std::string, nc_color> hp_bar = get_hp_bar( get_part_hp_cur( bp ), get_part_hp_max( bp ),
6656 false );
6657
6658 ss += colorize( left_justify( bp_heading, longest ), name_color );
6659 ss += colorize( hp_bar.first, hp_bar.second );
6660 // Trailing bars. UGLY!
6661 // TODO: Integrate into get_hp_bar somehow
6662 ss += colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white );
6663 ss += "\n";
6664 }
6665
6666 ss += "--\n";
6667 ss += _( "Wielding:" ) + std::string( " " );
6668 if( weapon.is_null() ) {
6669 ss += _( "Nothing" );
6670 } else {
6671 ss += weapon.tname();
6672 }
6673
6674 ss += "\n";
6675 ss += _( "Wearing:" ) + std::string( " " );
6676 ss += enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) {
6677 return it.tname();
6678 } );
6679
6680 return replace_colors( ss );
6681}
std::string left_justify(const std::string &str, const int width, const bool ignore_tags)
bool male
Definition: character.h:1513
std::string replace_colors(std::string text)
Replace special color tags (e.g.

References _, body_part_name_as_heading(), c_white, colorize(), enumerate_as_string(), Creature::get_all_body_parts(), get_hp_bar(), Creature::get_part_hp_cur(), Creature::get_part_hp_max(), int_id< T >::id(), item::is_null(), Creature::is_player(), left_justify(), limb_color(), male, name, replace_colors(), string_format(), item::tname(), utf8_width(), weapon, and worn.

Referenced by npc::extended_description().

◆ extraEncumbrance()

int Character::extraEncumbrance ( layer_level  level,
int  bp 
) const

Get encumbrance penalty per layer & body part.

Definition at line 3693 of file character.cpp.

3694{
3695 return encumbrance_cache->elems[bp].layer_penalty_details[static_cast<int>( level )].total;
3696}

References encumbrance_cache.

◆ fall_asleep() [1/2]

void Character::fall_asleep ( )

Adds "sleep" to the player.

Definition at line 9286 of file character.cpp.

9287{
9288 // Communicate to the player that he is using items on the floor
9289 std::string item_name = is_snuggling();
9290 if( item_name == "many" ) {
9291 if( one_in( 15 ) ) {
9292 add_msg_if_player( _( "You nestle your pile of clothes for warmth." ) );
9293 } else {
9294 add_msg_if_player( _( "You use your pile of clothes for warmth." ) );
9295 }
9296 } else if( item_name != "nothing" ) {
9297 if( one_in( 15 ) ) {
9298 add_msg_if_player( _( "You snuggle your %s to keep warm." ), item_name );
9299 } else {
9300 add_msg_if_player( _( "You use your %s to keep warm." ), item_name );
9301 }
9302 }
9304 if( get_stored_kcal() > max_stored_kcal() - bmr() / 4 &&
9306 if( is_avatar() ) {
9307 g->memorial().add( pgettext( "memorial_male", "Entered hibernation." ),
9308 pgettext( "memorial_female", "Entered hibernation." ) );
9309 }
9310
9311 add_msg_if_player( _( "You enter hibernation." ) );
9312 fall_asleep( 7_days );
9313 } else {
9315 _( "You need to be nearly full of food and water to enter hibernation." ) );
9316 }
9317 }
9318
9319 fall_asleep( 10_hours ); // default max sleep time.
9320}
static const trait_id trait_HIBERNATE("HIBERNATE")
int bmr() const
Definition: character.cpp:6980
std::string is_snuggling() const
Checks to see if the player is using floor items to keep warm, and return the name of one such item i...
Definition: character.cpp:9339

References _, Creature::add_msg_if_player(), bmr(), fall_asleep(), g, get_stored_kcal(), get_thirst(), has_active_mutation(), Creature::is_avatar(), is_snuggling(), m_bad, max_stored_kcal(), one_in(), pgettext(), thirsty, and trait_HIBERNATE.

Referenced by check_needs_extremes(), fall_asleep(), iexamine::flower_poppy(), player::hardcoded_effects(), introduce_into_anesthesia(), marloss_common(), iuse::mycus(), player::process_one_effect(), suffer_from_stimulants(), suffer_while_awake(), try_reject_mutagen(), activity_handlers::try_sleep_do_turn(), and mutagen_iv_actor::use().

◆ fall_asleep() [2/2]

void Character::fall_asleep ( const time_duration duration)

Definition at line 9322 of file character.cpp.

9323{
9324 if( activity ) {
9325 if( activity.id() == ACT_TRY_SLEEP ) {
9327 } else {
9329 }
9330 }
9331 add_effect( effect_sleep, duration );
9332}
void cancel_activity()
Definition: character.cpp:9246
void set_to_null()
This replaces the former usage act.type = ACT_NULL

References ACT_TRY_SLEEP, activity, Creature::add_effect(), cancel_activity(), effect_sleep, player_activity::id(), and player_activity::set_to_null().

◆ feed_furnace_with()

bool Character::feed_furnace_with ( item it)

Definition at line 1339 of file consumption.cpp.

1340{
1341 if( !can_feed_furnace_with( it ) ) {
1342 return false;
1343 }
1344 if( it.is_favorite &&
1345 !g->u.query_yn( _( "Are you sure you want to eat your favorited %s?" ), it.tname() ) ) {
1346 return false;
1347 }
1348
1349 const int consumed_charges = std::min( it.charges, it.charges_per_volume( furnace_max_volume ) );
1351
1352 if( energy == 0 ) {
1354 _( "You digest your %s, but fail to acquire energy from it." ),
1355 _( "<npcname> digests their %s for energy, but fails to acquire energy from it." ),
1356 it.tname() );
1357 } else if( is_max_power() ) {
1359 _( "You digest your %s, but you're fully powered already, so the energy is wasted." ),
1360 _( "<npcname> digests a %s for energy, they're fully powered already, so the energy is wasted." ),
1361 it.tname() );
1362 } else {
1363 const int profitable_energy = std::min( energy,
1365 if( it.count_by_charges() ) {
1367 vgettext( "You digest %d %s and recharge %d point of energy.",
1368 "You digest %d %s and recharge %d points of energy.",
1369 profitable_energy
1370 ),
1371 vgettext( "<npcname> digests %d %s and recharges %d point of energy.",
1372 "<npcname> digests %d %s and recharges %d points of energy.",
1373 profitable_energy
1374 ), consumed_charges, it.tname(), profitable_energy
1375 );
1376 } else {
1378 vgettext( "You digest your %s and recharge %d point of energy.",
1379 "You digest your %s and recharge %d points of energy.",
1380 profitable_energy
1381 ),
1382 vgettext( "<npcname> digests a %s and recharges %d point of energy.",
1383 "<npcname> digests a %s and recharges %d points of energy.",
1384 profitable_energy
1385 ), it.tname(), profitable_energy
1386 );
1387 }
1388 mod_power_level( units::from_kilojoule( profitable_energy ) );
1389 }
1390
1391 it.charges -= consumed_charges;
1392 mod_moves( -250 );
1393
1394 return true;
1395}
int get_acquirable_energy(const item &it, rechargeable_cbm cbm) const
bool can_feed_furnace_with(const item &it) const
bool is_max_power() const
Definition: character.cpp:2007
bool is_favorite
Definition: item.h:2234
quantity< int, energy_in_joule_tag > energy
Definition: units_energy.h:16
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, Creature::add_msg_player_or_npc(), can_feed_furnace_with(), item::charges, item::charges_per_volume(), item::count_by_charges(), units::from_kilojoule(), furnace, furnace_max_volume, g, get_acquirable_energy(), get_max_power_level(), get_power_level(), item::is_favorite, is_max_power(), m_info, Creature::mod_moves(), mod_power_level(), item::tname(), units::to_kilojoule(), and vgettext().

Referenced by player::consume_item().

◆ feed_reactor_with()

bool Character::feed_reactor_with ( item it)

Recharge CBMs whenever possible.

Returns
true when recharging was successful.

Definition at line 1295 of file consumption.cpp.

1296{
1297 if( !can_feed_reactor_with( it ) ) {
1298 return false;
1299 }
1300
1301 const auto iter = plut_charges.find( it.typeId() );
1302 const int max_amount = iter != plut_charges.end() ? iter->second : 0;
1303 const int amount = std::min( get_acquirable_energy( it, rechargeable_cbm::reactor ), max_amount );
1304
1305 if( amount >= PLUTONIUM_CHARGES * 10 &&
1306 !query_yn( _( "That is a LOT of plutonium. Are you sure you want that much?" ) ) ) {
1307 return false;
1308 }
1309
1310 add_msg_player_or_npc( _( "You add your %s to your reactor's tank." ),
1311 _( "<npcname> pours %s into their reactor's tank." ),
1312 it.tname() );
1313
1314 // TODO: Encapsulate
1315 tank_plut += amount;
1316 it.charges -= 1;
1317 mod_moves( -250 );
1318 return true;
1319}
bool can_feed_reactor_with(const item &it) const
Determine character's capability of recharging their CBMs.
const std::map< itype_id, int > plut_charges
static constexpr int PLUTONIUM_CHARGES

References _, Creature::add_msg_player_or_npc(), can_feed_reactor_with(), item::charges, get_acquirable_energy(), Creature::mod_moves(), plut_charges, PLUTONIUM_CHARGES, query_yn(), reactor, tank_plut, item::tname(), and item::typeId().

Referenced by player::consume_item().

◆ find_ammo()

std::vector< item_location > Character::find_ammo ( const item obj,
bool  empty = true,
int  radius = 1 
) const

Searches for ammo or magazines that can be used to reload obj.

Parameters
objitem to be reloaded. By design any currently loaded ammunition or magazine is ignored
emptywhether empty magazines should be considered as possible ammo
radiusadjacent map/vehicle tiles to search. 0 for only player tile, -1 for only inventory

Definition at line 2679 of file character.cpp.

2680{
2681 std::vector<item_location> res;
2682
2683 find_ammo_helper( const_cast<Character &>( *this ), obj, empty, std::back_inserter( res ), true );
2684
2685 if( radius >= 0 ) {
2686 for( auto &cursor : map_selector( pos(), radius ) ) {
2687 find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
2688 }
2689 for( auto &cursor : vehicle_selector( pos(), radius ) ) {
2690 find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
2691 }
2692 }
2693
2694 return res;
2695}
void find_ammo_helper(T &src, const item &obj, bool empty, Output out, bool nested)
Definition: character.cpp:2595

References find_ammo_helper(), and pos().

Referenced by ammo_count_for(), item::color_in_inventory(), and player::list_ammo().

◆ find_reloadables()

std::vector< item_location > Character::find_reloadables ( )

Searches for weapons and magazines that can be reloaded.

Definition at line 2697 of file character.cpp.

2698{
2699 std::vector<item_location> reloadables;
2700
2701 visit_items( [this, &reloadables]( item * node ) {
2702 if( node->is_holster() ) {
2703 return VisitResponse::NEXT;
2704 }
2705 bool reloadable = false;
2706 if( node->is_gun() && !node->magazine_compatible().empty() ) {
2707 reloadable = node->magazine_current() == nullptr ||
2708 node->ammo_remaining() < node->ammo_capacity();
2709 } else {
2710 reloadable = ( node->is_magazine() || node->is_bandolier() ||
2711 ( node->is_gun() && node->magazine_integral() ) ) &&
2712 node->ammo_remaining() < node->ammo_capacity();
2713 }
2714 if( reloadable ) {
2715 reloadables.push_back( item_location( *this, node ) );
2716 }
2717 return VisitResponse::SKIP;
2718 } );
2719 return reloadables;
2720}
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7533
bool is_holster() const
Definition: item.cpp:6421
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:422

References item::is_gun(), item::is_holster(), item::magazine_compatible(), SKIP, and visitable< Character >::visit_items().

Referenced by game::reload_weapon().

◆ find_remote_fuel()

itype_id Character::find_remote_fuel ( bool  look_only = false)

Find fuel used by remote powered bionic.

Definition at line 1358 of file bionics.cpp.

1359{
1360 itype_id remote_fuel;
1361 map &here = get_map();
1362
1363 const std::vector<item *> cables = items_with( []( const item & it ) {
1364 return it.active && it.has_flag( flag_CABLE_SPOOL );
1365 } );
1366
1367 for( const item *cable : cables ) {
1368
1369 const cata::optional<tripoint> target = cable->get_cable_target( this, pos() );
1370 if( !target ) {
1371 if( here.is_outside( pos() ) && !is_night( calendar::turn ) &&
1372 cable->get_var( "state" ) == "solar_pack_link" ) {
1373 if( !look_only ) {
1374 set_value( "sunlight", "1" );
1375 }
1376 remote_fuel = fuel_type_sun_light;
1377 }
1378
1379 if( cable->get_var( "state" ) == "UPS_link" ) {
1380 static const item_filter used_ups = [&]( const item & itm ) {
1381 return itm.get_var( "cable" ) == "plugged_in";
1382 };
1383 if( !look_only ) {
1384 if( has_charges( itype_UPS_off, 1, used_ups ) ) {
1386 units::to_kilojoule( max_power_level ), used_ups ) ) );
1387 } else if( has_charges( itype_adv_UPS_off, 1, used_ups ) ) {
1389 units::to_kilojoule( max_power_level ), used_ups ) ) );
1390 } else {
1391 set_value( "rem_battery", std::to_string( 0 ) );
1392 }
1393 }
1394 remote_fuel = fuel_type_battery;
1395 }
1396 continue;
1397 }
1398 const optional_vpart_position vp = here.veh_at( *target );
1399 if( !vp ) {
1400 continue;
1401 }
1402 if( !look_only ) {
1403 set_value( "rem_battery", std::to_string( vp->vehicle().fuel_left( fuel_type_battery,
1404 true ) ) );
1405 }
1406 remote_fuel = fuel_type_battery;
1407 }
1408
1409 return remote_fuel;
1410}
static const itype_id fuel_type_battery("battery")
bool is_night(const time_point &p)
Returns true if it's currently night time - after dusk and before dawn.
Definition: calendar.cpp:137
units::energy max_power_level
Definition: character.h:2177
bool is_outside(const tripoint &p) const
Definition: map.cpp:2558

References item::active, visitable< Character >::charges_of(), flag_CABLE_SPOOL(), fuel_type_battery, fuel_type_sun_light, get_map(), has_charges(), item::has_flag(), is_night(), map::is_outside(), visitable< Character >::items_with(), itype_adv_UPS_off, itype_UPS_off, max_power_level, pos(), Creature::set_value(), units::to_kilojoule(), to_string(), calendar::turn, and map::veh_at().

Referenced by burn_fuel(), iuse::cable_attach(), draw_bionics_titlebar(), and process_bionic().

◆ flag_encumbrance()

void Character::flag_encumbrance ( )

Flag encumbrance for updating.

Definition at line 1839 of file character.cpp.

1840{
1841 check_encumbrance = true;
1842}

References check_encumbrance.

Referenced by item::on_pickup(), and item::on_wield().

◆ floor_bedding_warmth()

int Character::floor_bedding_warmth ( const tripoint pos)
static

Warmth from terrain, furniture, vehicle furniture and traps.

Can be negative.

Definition at line 9479 of file character.cpp.

9480{
9481 map &here = get_map();
9482 const trap &trap_at_pos = here.tr_at( pos );
9483 const ter_id ter_at_pos = here.ter( pos );
9484 const furn_id furn_at_pos = here.furn( pos );
9485 int floor_bedding_warmth = 0;
9486
9487 const optional_vpart_position vp = here.veh_at( pos );
9488 const cata::optional<vpart_reference> boardable = vp.part_with_feature( "BOARDABLE", true );
9489 // Search the floor for bedding
9490 if( furn_at_pos != f_null ) {
9492 } else if( !trap_at_pos.is_null() ) {
9494 } else if( boardable ) {
9495 floor_bedding_warmth += boardable->info().floor_bedding_warmth;
9496 } else if( ter_at_pos == t_improvised_shelter ) {
9497 floor_bedding_warmth -= 500;
9498 } else {
9499 floor_bedding_warmth -= 2000;
9500 }
9501
9502 return floor_bedding_warmth;
9503}
static int floor_bedding_warmth(const tripoint &pos)
Warmth from terrain, furniture, vehicle furniture and traps.
Definition: character.cpp:9479
ter_id ter(const tripoint &p) const
Definition: map.cpp:1493
int floor_bedding_warmth
Definition: mapdata.h:498
int floor_bedding_warmth
Definition: trap.h:120

References f_null, floor_bedding_warmth(), furn_t::floor_bedding_warmth, trap::floor_bedding_warmth, map::furn(), get_map(), trap::is_null(), int_id< T >::obj(), optional_vpart_position::part_with_feature(), pos(), t_improvised_shelter, map::ter(), map::tr_at(), and map::veh_at().

Referenced by floor_bedding_warmth(), and floor_warmth().

◆ floor_item_warmth()

int Character::floor_item_warmth ( const tripoint pos)
static

Warmth from clothing on the floor.

Definition at line 9505 of file character.cpp.

9506{
9507 int item_warmth = 0;
9508
9509 const auto warm = [&item_warmth]( const auto & stack ) {
9510 for( const item &elem : stack ) {
9511 if( !elem.is_armor() ) {
9512 continue;
9513 }
9514 // Items that are big enough and covers the torso are used to keep warm.
9515 // Smaller items don't do as good a job
9516 if( elem.volume() > 250_ml &&
9517 ( elem.covers( bp_torso ) || elem.covers( bp_leg_l ) ||
9518 elem.covers( bp_leg_r ) ) ) {
9519 item_warmth += 60 * elem.get_warmth() * elem.volume() / 2500_ml;
9520 }
9521 }
9522 };
9523
9524 map &here = get_map();
9525 if( !!here.veh_at( pos ) ) {
9527 false ) ) {
9528 vehicle *const veh = &vp->vehicle();
9529 const int cargo = vp->part_index();
9530 vehicle_stack vehicle_items = veh->get_items( cargo );
9531 warm( vehicle_items );
9532 }
9533 return item_warmth;
9534 }
9535 map_stack floor_items = here.i_at( pos );
9536 warm( floor_items );
9537 return item_warmth;
9538}
A vehicle as a whole with all its components.
Definition: vehicle.h:675
vehicle(const vproto_id &type_id, int init_veh_fuel=-1, int init_veh_status=-1)
Definition: vehicle.cpp:251
vehicle_stack get_items(int part) const
Definition: vehicle.cpp:5468
@ VPFLAG_CARGO
Definition: veh_type.h:62

References bp_leg_l, bp_leg_r, bp_torso, vehicle::get_items(), get_map(), map::i_at(), optional_vpart_position::part_with_feature(), pos(), map::veh_at(), vehicle::vehicle(), and VPFLAG_CARGO.

Referenced by floor_warmth().

◆ floor_warmth()

int Character::floor_warmth ( const tripoint pos) const

Final warmth from the floor.

Definition at line 9540 of file character.cpp.

9541{
9542 const int item_warmth = floor_item_warmth( pos );
9543 int bedding_warmth = floor_bedding_warmth( pos );
9544
9545 // If the PC has fur, etc, that will apply too
9546 int floor_mut_warmth = bodytemp_modifier_traits_floor();
9547 // DOWN does not provide floor insulation, though.
9548 // Better-than-light fur or being in one's shell does.
9549 if( ( !( has_trait( trait_DOWN ) ) ) && ( floor_mut_warmth >= 200 ) ) {
9550 bedding_warmth = std::max( 0, bedding_warmth );
9551 }
9552 return ( item_warmth + bedding_warmth + floor_mut_warmth );
9553}
static const trait_id trait_DOWN("DOWN")
static int floor_item_warmth(const tripoint &pos)
Warmth from clothing on the floor.
Definition: character.cpp:9505
int bodytemp_modifier_traits_floor() const
Correction factor of the body temperature due to traits and mutations for player lying on the floor.
Definition: character.cpp:9564

References bodytemp_modifier_traits_floor(), floor_bedding_warmth(), floor_item_warmth(), has_trait(), pos(), and trait_DOWN.

Referenced by update_bodytemp().

◆ footwear_factor()

double Character::footwear_factor ( ) const

Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither.

Definition at line 8949 of file character.cpp.

8950{
8951 double ret = 0;
8952 if( wearing_something_on( bodypart_id( "foot_l" ) ) ) {
8953 ret += .5;
8954 }
8955 if( wearing_something_on( bodypart_id( "foot_r" ) ) ) {
8956 ret += .5;
8957 }
8958 return ret;
8959}

References cata::hash64_detail::ret, and wearing_something_on().

Referenced by is_immune_effect(), game::knockback(), rooted(), run_cost(), and game::walk_move().

◆ forced_dismount()

void Character::forced_dismount ( )

Definition at line 1148 of file character.cpp.

1149{
1151 bool mech = false;
1152 if( mounted_creature ) {
1153 auto mon = mounted_creature.get();
1154 if( mon->has_flag( MF_RIDEABLE_MECH ) && !mon->type->mech_weapon.is_empty() ) {
1155 mech = true;
1157 }
1158 mon->mounted_player_id = character_id();
1159 mon->remove_effect( effect_ridden );
1160 mon->add_effect( effect_ai_waiting, 5_turns );
1161 mounted_creature = nullptr;
1162 mon->mounted_player = nullptr;
1163 }
1164 std::vector<tripoint> valid;
1165 for( const tripoint &jk : get_map().points_in_radius( pos(), 1 ) ) {
1166 if( g->is_empty( jk ) ) {
1167 valid.push_back( jk );
1168 }
1169 }
1170 if( !valid.empty() ) {
1171 setpos( random_entry( valid ) );
1172 if( mech ) {
1173 add_msg_player_or_npc( m_bad, _( "You are ejected from your mech!" ),
1174 _( "<npcname> is ejected from their mech!" ) );
1175 } else {
1176 add_msg_player_or_npc( m_bad, _( "You fall off your mount!" ),
1177 _( "<npcname> falls off their mount!" ) );
1178 }
1179 const int dodge = get_dodge();
1180 const int damage = std::max( 0, rng( 1, 20 ) - rng( dodge, dodge * 2 ) );
1181 bodypart_id hit( "num_bp" );
1182 switch( rng( 1, 10 ) ) {
1183 case 1:
1184 if( one_in( 2 ) ) {
1185 hit = bodypart_id( "foot_l" );
1186 } else {
1187 hit = bodypart_id( "foot_r" );
1188 }
1189 break;
1190 case 2:
1191 case 3:
1192 case 4:
1193 if( one_in( 2 ) ) {
1194 hit = bodypart_id( "leg_l" );
1195 } else {
1196 hit = bodypart_id( "leg_r" );
1197 }
1198 break;
1199 case 5:
1200 case 6:
1201 case 7:
1202 if( one_in( 2 ) ) {
1203 hit = bodypart_id( "arm_l" );
1204 } else {
1205 hit = bodypart_id( "arm_r" );
1206 }
1207 break;
1208 case 8:
1209 case 9:
1210 hit = bodypart_id( "torso" );
1211 break;
1212 case 10:
1213 hit = bodypart_id( "head" );
1214 break;
1215 }
1216 if( damage > 0 ) {
1217 add_msg_if_player( m_bad, _( "You hurt yourself!" ) );
1218 deal_damage( nullptr, hit, damage_instance( DT_BASH, damage ) );
1219 if( is_avatar() ) {
1220 g->memorial().add(
1221 pgettext( "memorial_male", "Fell off a mount." ),
1222 pgettext( "memorial_female", "Fell off a mount." ) );
1223 }
1225 }
1226 add_effect( effect_downed, 5_turns, num_bp );
1227 } else {
1228 add_msg( m_debug, "Forced_dismount could not find a square to deposit player" );
1229 }
1230 if( is_avatar() ) {
1231 if( g->u.get_grab_type() != OBJECT_NONE ) {
1232 add_msg( m_warning, _( "You let go of the grabbed object." ) );
1233 g->u.grab( OBJECT_NONE );
1234 }
1236 if( g->u.is_auto_moving() || g->u.has_destination() || g->u.has_destination_activity() ) {
1237 g->u.clear_destination();
1238 }
1239 g->update_map( g->u );
1240 }
1241 if( activity ) {
1243 }
1244 moves -= 150;
1245}
static const efftype_id effect_downed("downed")
dealt_damage_instance deal_damage(Creature *source, bodypart_id bp, const damage_instance &d) override
Calls Creature::deal_damage and handles damaged effects (waking up, etc.)
Definition: character.cpp:8473
float get_dodge() const override
Definition: melee.cpp:811
void check_dead_state()
This function checks the creatures is_dead_state and (if true) calls die.
Definition: creature.cpp:1839

References _, activity, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), cancel_activity(), character_id, Creature::check_dead_state(), CMM_WALK, deal_damage(), DT_BASH, effect_ai_waiting, effect_downed, effect_ridden, effect_riding, g, get_dodge(), get_map(), Creature::is_avatar(), m_bad, m_debug, m_warning, MF_RIDEABLE_MECH, mounted_creature, Creature::moves, num_bp, OBJECT_NONE, one_in(), pgettext(), points_in_radius(), pos(), random_entry(), Creature::remove_effect(), visitable< Character >::remove_item(), rng(), set_movement_mode(), setpos(), and weapon.

Referenced by Creature::add_effect(), monster::die(), avatar::invoke_item(), and monster::setpos().

◆ fuel_bionic_with()

bool Character::fuel_bionic_with ( item it)

Definition at line 1397 of file consumption.cpp.

1398{
1399 if( !can_fuel_bionic_with( it ) ) {
1400 return false;
1401 }
1402
1404
1405 const int loadable = std::min( it.charges, get_fuel_capacity( it.typeId() ) );
1406 const std::string str_loaded = get_value( it.typeId().str() );
1407 int loaded = 0;
1408 if( !str_loaded.empty() ) {
1409 loaded = std::stoi( str_loaded );
1410 }
1411
1412 const std::string new_charge = std::to_string( loadable + loaded );
1413
1414 it.charges -= loadable;
1415 // Type and amount of fuel
1416 set_value( it.typeId().str(), new_charge );
1419 //~ %1$i: charge number, %2$s: item name, %3$s: bionics name
1420 vgettext( "You load %1$i charge of %2$s in your %3$s.",
1421 "You load %1$i charges of %2$s in your %3$s.", loadable ),
1422 //~ %1$i: charge number, %2$s: item name, %3$s: bionics name
1423 vgettext( "<npcname> load %1$i charge of %2$s in their %3$s.",
1424 "<npcname> load %1$i charges of %2$s in their %3$s.", loadable ), loadable, it.tname(), bio->name );
1425 mod_moves( -250 );
1426 return true;
1427}
bionic_id get_most_efficient_bionic(const std::vector< bionic_id > &bids) const
Return bionic_id of bionic of most fuel efficient bionic.
Definition: character.cpp:1957
bool can_fuel_bionic_with(const item &it) const
Returns true if the character can fuel a bionic with the item.
Definition: character.cpp:1915
int get_fuel_capacity(const itype_id &fuel) const
Return available space to store specified fuel.
Definition: character.cpp:2091

References Creature::add_msg_player_or_npc(), can_fuel_bionic_with(), item::charges, get_bionic_fueled_with(), get_fuel_capacity(), get_most_efficient_bionic(), Creature::get_value(), m_info, Creature::mod_moves(), bionic_data::name, Creature::set_value(), string_id< T >::str(), item::tname(), to_string(), item::typeId(), update_fuel_storage(), and vgettext().

Referenced by player::consume_item().

◆ fun_for()

std::pair< int, int > Character::fun_for ( const item comest) const

Handles the enjoyability value for a comestible.

First value is enjoyability, second is cap.

Definition at line 465 of file consumption.cpp.

466{
467 if( !comest.is_comestible() ) {
468 return std::pair<int, int>( 0, 0 );
469 }
470
471 // As float to avoid rounding too many times
472 float fun = comest.get_comestible_fun();
473 // Rotten food should be pretty disgusting
474 const float relative_rot = comest.get_relative_rot();
475 if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) && !has_trait( trait_SAPROVORE ) ) {
476 fun -= 10;
477 if( fun > 0 ) {
478 fun *= 0.5f;
479 } else {
480 fun *= 2.0f;
481 }
482 }
483
484 // Food is less enjoyable when eaten too often.
485 if( fun > 0 || comest.has_flag( flag_NEGATIVE_MONOTONY_OK ) ) {
486 for( const consumption_event &event : consumption_history->elems ) {
487 if( event.time > calendar::turn - 2_days && event.type_id == comest.typeId() &&
488 event.component_hash == comest.make_component_hash() ) {
489 fun -= comest.get_comestible()->monotony_penalty;
490 // This effect can't drop fun below 0, unless the food has the right flag.
491 // 0 is the lowest we'll go, no need to keep looping.
492 if( fun <= 0 && !comest.has_flag( flag_NEGATIVE_MONOTONY_OK ) ) {
493 fun = 0;
494 break;
495 }
496 }
497 }
498 }
499
500 float fun_max = fun < 0 ? fun * 6 : fun * 3;
501
502 if( ( comest.has_flag( flag_LUPINE ) && has_trait( trait_THRESH_LUPINE ) ) ||
503 ( comest.has_flag( flag_FELINE ) && has_trait( trait_THRESH_FELINE ) ) ) {
504 if( fun < 0 ) {
505 fun = -fun;
506 fun /= 2;
507 }
508 }
509
510 if( has_trait( trait_GOURMAND ) ) {
511 if( fun < -1 ) {
512 fun_max = fun;
513 fun /= 2;
514 } else if( fun > 0 ) {
515 fun_max *= 3;
516 fun = fun * 3 / 2;
517 }
518 }
519
522 fun < 0 ) {
523 fun = 0;
524 }
525
526 return { static_cast< int >( fun ), static_cast< int >( fun_max ) };
527}
pimpl< consumption_history_t > consumption_history
Definition: character.h:1536
uint64_t make_component_hash() const
Creates a hash from the itype_ids of this item's components.
Definition: item.cpp:8749
int get_comestible_fun() const
Definition: item.cpp:5365
static const bionic_id bio_taste_blocker("bio_taste_blocker")
static const std::string flag_NEGATIVE_MONOTONY_OK("NEGATIVE_MONOTONY_OK")
static const trait_id trait_GOURMAND("GOURMAND")
time_point time
Definition: consumption.h:15
uint64_t component_hash
Definition: consumption.h:17
itype_id type_id
Definition: consumption.h:16

References bio_taste_blocker, consumption_event::component_hash, consumption_history, flag_FELINE(), flag_LUPINE(), flag_NEGATIVE_MONOTONY_OK(), units::from_kilojoule(), item::get_comestible(), item::get_comestible_fun(), get_power_level(), item::get_relative_rot(), has_active_bionic(), item::has_flag(), has_trait(), item::is_comestible(), item::make_component_hash(), consumption_event::time, trait_GOURMAND, trait_SAPROPHAGE, trait_SAPROVORE, trait_THRESH_FELINE, trait_THRESH_LUPINE, calendar::turn, consumption_event::type_id, and item::typeId().

Referenced by comestible_inventory_preset::comestible_inventory_preset(), find_auto_consume(), and modify_morale().

◆ get_acquirable_energy() [1/2]

int Character::get_acquirable_energy ( const item it) const

Definition at line 1492 of file consumption.cpp.

1493{
1495}

References get_acquirable_energy(), and get_cbm_rechargeable_with().

◆ get_acquirable_energy() [2/2]

int Character::get_acquirable_energy ( const item it,
rechargeable_cbm  cbm 
) const

Definition at line 1446 of file consumption.cpp.

1447{
1448 switch( cbm ) {
1450 break;
1451
1453 if( it.charges > 0 ) {
1454 const auto iter = plut_charges.find( it.typeId() );
1455 return iter != plut_charges.end() ? it.charges * iter->second : 0;
1456 }
1457
1458 break;
1459
1461 units::volume consumed_vol = it.volume();
1462 units::mass consumed_mass = it.weight();
1464 const double n_stacks = static_cast<double>( it.charges_per_volume( furnace_max_volume ) ) /
1465 it.type->stack_size;
1466 consumed_vol = it.type->volume * n_stacks;
1467 // it.type->weight is in 10g units?
1468 consumed_mass = it.type->weight * 10 * n_stacks;
1469 }
1470 int amount = ( consumed_vol / 250_ml + consumed_mass / 1_gram ) / 9;
1471
1472 // TODO: JSONize.
1473 if( it.made_of( material_id( "leather" ) ) ) {
1474 amount /= 4;
1475 }
1476 if( it.made_of( material_id( "wood" ) ) ) {
1477 amount /= 2;
1478 }
1479
1480 return amount;
1481 }
1484 const int to_consume = std::min( it.charges, bid->fuel_capacity );
1485 const int to_charge = static_cast<int>( it.fuel_energy() * to_consume * bid->fuel_efficiency );
1486 return to_charge;
1487 }
1488
1489 return 0;
1490}
int fuel_capacity
How much fuel this bionic can hold.
Definition: bionics.h:65
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:965
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:982
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:974

References item::charges, item::charges_per_volume(), item::count_by_charges(), bionic_data::fuel_capacity, bionic_data::fuel_efficiency, item::fuel_energy(), furnace, furnace_max_volume, get_bionic_fueled_with(), get_most_efficient_bionic(), item::made_of(), none, other, plut_charges, reactor, itype::stack_size, item::type, item::typeId(), item::volume(), itype::volume, item::weight(), and itype::weight.

Referenced by feed_furnace_with(), feed_reactor_with(), and get_acquirable_energy().

◆ get_aim_types()

std::vector< aim_type > Character::get_aim_types ( const item gun) const

Definition at line 1628 of file ranged.cpp.

1629{
1630 std::vector<aim_type> aim_types = get_default_aim_type();
1631 if( !gun.is_gun() ) {
1632 return aim_types;
1633 }
1634 int sight_dispersion = effective_dispersion( gun.sight_dispersion() );
1635 // Aiming thresholds are dependent on weapon sight dispersion, attempting to place thresholds
1636 // at 10%, 5% and 0% of the difference between MAX_RECOIL and sight dispersion.
1637 std::vector<int> thresholds = {
1638 static_cast<int>( ( ( MAX_RECOIL - sight_dispersion ) / 10.0 ) + sight_dispersion ),
1639 static_cast<int>( ( ( MAX_RECOIL - sight_dispersion ) / 20.0 ) + sight_dispersion ),
1640 static_cast<int>( sight_dispersion )
1641 };
1642 // Remove duplicate thresholds.
1643 std::vector<int>::iterator thresholds_it = std::adjacent_find( thresholds.begin(),
1644 thresholds.end() );
1645 while( thresholds_it != thresholds.end() ) {
1646 thresholds.erase( thresholds_it );
1647 thresholds_it = std::adjacent_find( thresholds.begin(), thresholds.end() );
1648 }
1649 thresholds_it = thresholds.begin();
1650 aim_types.push_back( aim_type { _( "Regular" ), "AIMED_SHOT", _( "[%c] to aim and fire." ),
1651 true, *thresholds_it } );
1652 thresholds_it++;
1653 if( thresholds_it != thresholds.end() ) {
1654 aim_types.push_back( aim_type { _( "Careful" ), "CAREFUL_SHOT",
1655 _( "[%c] to take careful aim and fire." ), true,
1656 *thresholds_it } );
1657 thresholds_it++;
1658 }
1659 if( thresholds_it != thresholds.end() ) {
1660 aim_types.push_back( aim_type { _( "Precise" ), "PRECISE_SHOT",
1661 _( "[%c] to take precise aim and fire." ), true,
1662 *thresholds_it } );
1663 }
1664 return aim_types;
1665}
int effective_dispersion(int dispersion) const
Definition: character.cpp:567
int sight_dispersion() const
Get lowest dispersion of either integral or any attached sights.
Definition: item.cpp:7094
static std::vector< aim_type > get_default_aim_type()
Definition: ranged.cpp:1327

References _, effective_dispersion(), get_default_aim_type(), item::is_gun(), MAX_RECOIL, and item::sight_dispersion().

Referenced by target_ui::init_window_and_input(), and print_aim().

◆ get_all_armor_type()

std::map< bodypart_id, int > Character::get_all_armor_type ( damage_type  dt,
const std::map< bodypart_id, std::vector< const item * > > &  clothing_map 
) const

Definition at line 7039 of file character.cpp.

7041{
7042 std::map<bodypart_id, int> ret;
7043 for( const bodypart_id &bp : get_all_body_parts() ) {
7044 ret.emplace( bp, 0 );
7045 }
7046
7047 for( std::pair<const bodypart_id, int> &per_bp : ret ) {
7048 const bodypart_id &bp = per_bp.first;
7049 switch( dt ) {
7050 case DT_TRUE:
7051 case DT_BIOLOGICAL:
7052 // Characters cannot resist this
7053 return ret;
7054 /* BASH, CUT, STAB, and BULLET don't benefit from the clothing_map optimization */
7055 // TODO: Fix that
7056 case DT_BASH:
7057 per_bp.second += get_armor_bash( bp );
7058 break;
7059 case DT_CUT:
7060 per_bp.second += get_armor_cut( bp );
7061 break;
7062 case DT_STAB:
7063 per_bp.second += get_armor_cut( bp ) * 0.8f;
7064 break;
7065 case DT_BULLET:
7066 per_bp.second += get_armor_bullet( bp );
7067 break;
7068 case DT_ACID:
7069 case DT_HEAT:
7070 case DT_COLD:
7071 case DT_ELECTRIC: {
7072 for( const item *it : clothing_map.at( bp ) ) {
7073 per_bp.second += it->damage_resist( dt );
7074 }
7075
7076 per_bp.second += mutation_armor( bp, dt );
7077 break;
7078 }
7079 case DT_NULL:
7080 case NUM_DT:
7081 debugmsg( "Invalid damage type: %d", dt );
7082 return ret;
7083 }
7084 }
7085
7086 return ret;
7087}
int get_armor_cut(bodypart_id bp) const override
Returns overall cutting resistance for the body_part.
Definition: character.cpp:6990
int get_armor_bullet(bodypart_id bp) const override
Returns overall bullet resistance for the body_part.
Definition: character.cpp:6995
int get_armor_bash(bodypart_id bp) const override
Returns overall bashing resistance for the body_part.
Definition: character.cpp:6985
resistances mutation_armor(bodypart_id bp) const
Returns resistances on a body part provided by mutations.
Definition: character.cpp:6510
@ DT_TRUE
Definition: damage.h:22
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32
@ DT_BIOLOGICAL
Definition: damage.h:23

References debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, Creature::get_all_body_parts(), get_armor_bash(), get_armor_bullet(), get_armor_cut(), mutation_armor(), NUM_DT, and cata::hash64_detail::ret.

Referenced by get_armor_fire().

◆ get_all_skills()

const SkillLevelMap & Character::get_all_skills ( ) const

Definition at line 3344 of file character.cpp.

3345{
3346 return *_skills;
3347}

References _skills.

Referenced by player::exceeds_recipe_requirements(), player::has_recipe_requirements(), set_skills(), and memorial_logger::write().

◆ get_ammo()

std::vector< const item * > Character::get_ammo ( const ammotype at) const

Returns the items that are ammo and have the matching ammo type.

Definition at line 2587 of file character.cpp.

2588{
2589 return items_with( [at]( const item & it ) {
2590 return it.ammo_type() == at;
2591 } );
2592}
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7425

References item::ammo_type(), and visitable< Character >::items_with().

Referenced by item::color_in_inventory(), and npc::decide_needs().

◆ get_armor_acid()

int Character::get_armor_acid ( bodypart_id  bp) const

Returns overall acid resistance for the body part.

Definition at line 7170 of file character.cpp.

7171{
7172 return get_armor_type( DT_ACID, bp );
7173}
int get_armor_type(damage_type dt, bodypart_id bp) const override
Returns overall resistance to given type on the bod part.
Definition: character.cpp:7001

References DT_ACID, and get_armor_type().

◆ get_armor_bash()

int Character::get_armor_bash ( bodypart_id  bp) const
overridevirtual

Returns overall bashing resistance for the body_part.

Reimplemented from Creature.

Definition at line 6985 of file character.cpp.

6986{
6988}
int get_armor_bash_base(bodypart_id bp) const override
Returns bashing resistance from the creature and armor only.
Definition: character.cpp:7089
int armor_bash_bonus
Definition: creature.h:820

References Creature::armor_bash_bonus, and get_armor_bash_base().

Referenced by get_all_armor_type(), get_armor_type(), game::get_dangerous_tile(), and game::place_player().

◆ get_armor_bash_base()

int Character::get_armor_bash_base ( bodypart_id  bp) const
overridevirtual

Returns bashing resistance from the creature and armor only.

Reimplemented from Creature.

Definition at line 7089 of file character.cpp.

7090{
7091 int ret = 0;
7092 for( auto &i : worn ) {
7093 if( i.covers( bp->token ) ) {
7094 ret += i.bash_resist();
7095 }
7096 }
7097 for( const bionic_id &bid : get_bionics() ) {
7098 const auto bash_prot = bid->bash_protec.find( bp.id() );
7099 if( bash_prot != bid->bash_protec.end() ) {
7100 ret += bash_prot->second;
7101 }
7102 }
7103
7104 ret += mutation_armor( bp, DT_BASH );
7105 return ret;
7106}

References DT_BASH, get_bionics(), int_id< T >::id(), mutation_armor(), cata::hash64_detail::ret, and worn.

Referenced by get_armor_bash().

◆ get_armor_bullet()

int Character::get_armor_bullet ( bodypart_id  bp) const
overridevirtual

Returns overall bullet resistance for the body_part.

Reimplemented from Creature.

Definition at line 6995 of file character.cpp.

6996{
6998}
int get_armor_bullet_base(bodypart_id bp) const override
Returns cutting resistance from the creature and armor only.
Definition: character.cpp:7127
int armor_bullet_bonus
Definition: creature.h:822

References Creature::armor_bullet_bonus, and get_armor_bullet_base().

Referenced by get_all_armor_type(), and get_armor_type().

◆ get_armor_bullet_base()

int Character::get_armor_bullet_base ( bodypart_id  bp) const
overridevirtual

Returns cutting resistance from the creature and armor only.

Reimplemented from Creature.

Definition at line 7127 of file character.cpp.

7128{
7129 int ret = 0;
7130 for( auto &i : worn ) {
7131 if( i.covers( bp->token ) ) {
7132 ret += i.bullet_resist();
7133 }
7134 }
7135
7136 for( const bionic_id &bid : get_bionics() ) {
7137 const auto bullet_prot = bid->bullet_protec.find( bp.id() );
7138 if( bullet_prot != bid->bullet_protec.end() ) {
7139 ret += bullet_prot->second;
7140 }
7141 }
7142
7143 ret += mutation_armor( bp, DT_BULLET );
7144 return ret;
7145}

References DT_BULLET, get_bionics(), int_id< T >::id(), mutation_armor(), cata::hash64_detail::ret, and worn.

Referenced by get_armor_bullet().

◆ get_armor_cut()

int Character::get_armor_cut ( bodypart_id  bp) const
overridevirtual

Returns overall cutting resistance for the body_part.

Reimplemented from Creature.

Definition at line 6990 of file character.cpp.

6991{
6992 return get_armor_cut_base( bp ) + armor_cut_bonus;
6993}
int get_armor_cut_base(bodypart_id bp) const override
Returns cutting resistance from the creature and armor only.
Definition: character.cpp:7108
int armor_cut_bonus
Definition: creature.h:821

References Creature::armor_cut_bonus, and get_armor_cut_base().

Referenced by get_all_armor_type(), get_armor_type(), and map::player_in_field().

◆ get_armor_cut_base()

int Character::get_armor_cut_base ( bodypart_id  bp) const
overridevirtual

Returns cutting resistance from the creature and armor only.

Reimplemented from Creature.

Definition at line 7108 of file character.cpp.

7109{
7110 int ret = 0;
7111 for( auto &i : worn ) {
7112 if( i.covers( bp->token ) ) {
7113 ret += i.cut_resist();
7114 }
7115 }
7116 for( const bionic_id &bid : get_bionics() ) {
7117 const auto cut_prot = bid->cut_protec.find( bp.id() );
7118 if( cut_prot != bid->cut_protec.end() ) {
7119 ret += cut_prot->second;
7120 }
7121 }
7122
7123 ret += mutation_armor( bp, DT_CUT );
7124 return ret;
7125}

References DT_CUT, get_bionics(), int_id< T >::id(), mutation_armor(), cata::hash64_detail::ret, and worn.

Referenced by get_armor_cut().

◆ get_armor_fire()

std::map< bodypart_id, int > Character::get_armor_fire ( const std::map< bodypart_id, std::vector< const item * > > &  clothing_map) const

Returns overall fire resistance.

Definition at line 8400 of file character.cpp.

8402{
8403 return get_all_armor_type( DT_HEAT, clothing_map );
8404}
std::map< bodypart_id, int > get_all_armor_type(damage_type dt, const std::map< bodypart_id, std::vector< const item * > > &clothing_map) const
Definition: character.cpp:7039

References DT_HEAT, and get_all_armor_type().

Referenced by update_bodytemp().

◆ get_armor_type()

int Character::get_armor_type ( damage_type  dt,
bodypart_id  bp 
) const
overridevirtual

Returns overall resistance to given type on the bod part.

Implements Creature.

Definition at line 7001 of file character.cpp.

7002{
7003 switch( dt ) {
7004 case DT_TRUE:
7005 case DT_BIOLOGICAL:
7006 return 0;
7007 case DT_BASH:
7008 return get_armor_bash( bp );
7009 case DT_CUT:
7010 return get_armor_cut( bp );
7011 case DT_STAB:
7012 return get_armor_cut( bp ) * 0.8f;
7013 case DT_BULLET:
7014 return get_armor_bullet( bp );
7015 case DT_ACID:
7016 case DT_HEAT:
7017 case DT_COLD:
7018 case DT_ELECTRIC: {
7019 int ret = 0;
7020 for( auto &i : worn ) {
7021 if( i.covers( bp->token ) ) {
7022 ret += i.damage_resist( dt );
7023 }
7024 }
7025
7026 ret += mutation_armor( bp, dt );
7027 return ret;
7028 }
7029 case DT_NULL:
7030 case NUM_DT:
7031 // Let it error below
7032 break;
7033 }
7034
7035 debugmsg( "Invalid damage type: %d", dt );
7036 return 0;
7037}

References debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, get_armor_bash(), get_armor_bullet(), get_armor_cut(), mutation_armor(), NUM_DT, cata::hash64_detail::ret, and worn.

Referenced by map::burn_body_part(), get_armor_acid(), and is_immune_field().

◆ get_auto_move_route()

std::vector< tripoint > & Character::get_auto_move_route ( )

Definition at line 10525 of file character.cpp.

10526{
10527 return auto_move_route;
10528}

References auto_move_route.

Referenced by game::cancel_activity_or_ignore_query(), game::cancel_activity_query(), npc::move(), and npc::move_to().

◆ get_base_traits()

std::vector< trait_id > Character::get_base_traits ( ) const

Get the idents of all base traits.

Definition at line 2810 of file newcharacter.cpp.

2811{
2812 return std::vector<trait_id>( my_traits.begin(), my_traits.end() );
2813}

References my_traits.

Referenced by avatar::create(), and set_description().

◆ get_bionic_fueled_with()

std::vector< bionic_id > Character::get_bionic_fueled_with ( const item it) const

Return bionic_id of bionics able to use it as fuel.

Definition at line 1931 of file character.cpp.

1932{
1933 std::vector<bionic_id> bionics;
1934
1935 for( const bionic_id &bid : get_bionics() ) {
1936 for( const itype_id &fuel : bid->fuel_opts ) {
1937 if( fuel == it.typeId() ) {
1938 bionics.emplace_back( bid );
1939 }
1940 }
1941 }
1942
1943 return bionics;
1944}

References get_bionics(), and item::typeId().

Referenced by burn_move_stamina(), fuel_bionic_with(), get_acquirable_energy(), game::on_move_effects(), reset_remote_fuel(), and update_fuel_storage().

◆ get_bionics()

◆ get_cbm_rechargeable_with()

rechargeable_cbm Character::get_cbm_rechargeable_with ( const item it) const

Definition at line 1429 of file consumption.cpp.

1430{
1431 if( can_feed_reactor_with( it ) ) {
1433 }
1434
1435 if( can_feed_furnace_with( it ) ) {
1437 }
1438
1439 if( can_fuel_bionic_with( it ) ) {
1441 }
1442
1444}

References can_feed_furnace_with(), can_feed_reactor_with(), can_fuel_bionic_with(), furnace, none, other, and reactor.

Referenced by can_consume_for_bionic(), and get_acquirable_energy().

◆ get_check_encumbrance()

bool Character::get_check_encumbrance ( )
inline

Definition at line 1946 of file character.h.

1946 {
1947 return check_encumbrance;
1948 }

References check_encumbrance.

Referenced by player::process_items().

◆ get_consumable_from()

item & Character::get_consumable_from ( item it) const

Returns a reference to the item itself (if it's consumable), the first of its contents (if it's consumable) or null item otherwise.

WARNING: consumable does not necessarily guarantee the comestible type.

Definition at line 1522 of file consumption.cpp.

1523{
1524 if( !it.is_container_empty() && can_consume_as_is( it.contents.front() ) ) {
1525 return it.contents.front();
1526 } else if( can_consume_as_is( it ) ) {
1527 return it;
1528 }
1529
1530 static item null_comestible;
1531 // Since it's not const.
1532 null_comestible = item();
1533 return null_comestible;
1534}

References can_consume_as_is(), item::contents, item_contents::front(), and item::is_container_empty().

Referenced by player::consume_item(), and find_auto_consume().

◆ get_dependent_worn_items()

std::list< item * > Character::get_dependent_worn_items ( const item it) const

Returns all items that must be taken off before taking off this item.

Definition at line 2481 of file character.cpp.

2482{
2483 std::list<item *> dependent;
2484 // Adds dependent worn items recursively
2485 const std::function<void( const item &it )> add_dependent = [&]( const item & it ) {
2486 for( const item &wit : worn ) {
2487 if( &wit == &it || !wit.is_worn_only_with( it ) ) {
2488 continue;
2489 }
2490 const auto iter = std::find_if( dependent.begin(), dependent.end(),
2491 [&wit]( const item * dit ) {
2492 return &wit == dit;
2493 } );
2494 if( iter == dependent.end() ) { // Not in the list yet
2495 add_dependent( wit );
2496 dependent.push_back( const_cast<item *>( & wit ) );
2497 }
2498 }
2499 };
2500
2501 if( is_worn( it ) ) {
2502 add_dependent( it );
2503 }
2504
2505 return dependent;
2506}

References is_worn(), item::is_worn_only_with(), and worn.

Referenced by player::can_takeoff(), and pickup::reorder_for_dropping().

◆ get_destination_activity()

player_activity Character::get_destination_activity ( ) const

Definition at line 1028 of file character.cpp.

1029{
1030 return destination_activity;
1031}

References destination_activity.

Referenced by has_destination_activity(), has_distant_destination(), and start_destination_activity().

◆ get_dex()

◆ get_dex_base()

int Character::get_dex_base ( ) const
virtual

Reimplemented in avatar.

Definition at line 4101 of file character.cpp.

4102{
4103 return dex_max;
4104}

References dex_max.

Referenced by enchantment::activate_passive(), draw_stats_tab(), get_dex(), and avatar::get_dex_base().

◆ get_dex_bonus()

int Character::get_dex_bonus ( ) const
virtual

Definition at line 4118 of file character.cpp.

4119{
4120 return dex_bonus;
4121}

References dex_bonus.

Referenced by reset_stats().

◆ get_dodge()

float Character::get_dodge ( ) const
overridevirtual

Reimplemented from Creature.

Definition at line 811 of file melee.cpp.

812{
813 //If we're asleep or busy we can't dodge
815 return 0.0f;
816 }
817
818 float ret = Creature::get_dodge();
819 // Chop in half if we are unable to move
822 ret /= 2;
823 }
824
825 if( has_effect( effect_grabbed ) ) {
826 int zed_number = 0;
827 for( auto &dest : g->m.points_in_radius( pos(), 1, 0 ) ) {
828 const monster *const mon = g->critter_at<monster>( dest );
829 if( mon && mon->has_effect( effect_grabbing ) ) {
830 zed_number++;
831 }
832 }
833 ret *= 1.0f - ( 0.25f * zed_number );
834 }
835
836 if( worn_with_flag( "ROLLER_INLINE" ) ||
837 worn_with_flag( "ROLLER_QUAD" ) ||
838 worn_with_flag( "ROLLER_ONE" ) ) {
839 ret /= has_trait( trait_PROF_SKATER ) ? 2 : 5;
840 }
841
843 ret /= 4;
844 }
845
846 // Each dodge after the first subtracts equivalent of 2 points of dodge skill
847 if( dodges_left <= 0 ) {
848 ret += dodges_left * 2 - 2;
849 }
850
851 return std::max( 0.0f, ret );
852}
int dodges_left
Definition: character.h:558
virtual float get_dodge() const
Definition: creature.cpp:1508
static const efftype_id effect_lightsnare("lightsnare")
static const efftype_id effect_grabbing("grabbing")
static const efftype_id effect_bouldering("bouldering")
static const efftype_id effect_beartrap("beartrap")
static const efftype_id effect_grabbed("grabbed")
static const efftype_id effect_heavysnare("heavysnare")
static const trait_id trait_PROF_SKATER("PROF_SKATER")

References dodges_left, effect_beartrap, effect_bouldering, effect_grabbed, effect_grabbing, effect_heavysnare, effect_lightsnare, effect_narcosis, g, Creature::get_dodge(), Creature::has_effect(), has_trait(), in_sleep_state(), pos(), cata::hash64_detail::ret, trait_PROF_SKATER, and worn_with_flag().

Referenced by npc::character_danger(), trapfunc::crossbow(), player::dodge_roll(), draw_skills_tab(), forced_dismount(), trapfunc::pit(), trapfunc::pit_glass(), trapfunc::pit_spikes(), mattack::science(), trapfunc::shotgun(), and game::update_stair_monsters().

◆ get_dodge_base()

float Character::get_dodge_base ( ) const
overridevirtual

Combat getters.

Dexterity increases dodge base Dodge increases dodge_base

Implements Creature.

Definition at line 5851 of file character.cpp.

5852{
5853 /** @EFFECT_DEX increases dodge base */
5854 /** @EFFECT_DODGE increases dodge_base */
5855 return get_dex() / 2.0f + get_skill_level( skill_dodge );
5856}
static const skill_id skill_dodge("dodge")

References get_dex(), get_skill_level(), and skill_dodge.

◆ get_effective_efficiency()

float Character::get_effective_efficiency ( int  b,
float  fuel_efficiency 
)

Applies modifier to fuel_efficiency and returns the resulting efficiency.

Definition at line 1476 of file bionics.cpp.

1477{
1478 const bionic &bio = ( *my_bionics )[b];
1479 const cata::optional<float> &coverage_penalty = bio.info().coverage_power_gen_penalty;
1480 float effective_efficiency = fuel_efficiency;
1481 if( coverage_penalty ) {
1482 int coverage = 0;
1483 const std::map< bodypart_str_id, int > &occupied_bodyparts = bio.info().occupied_bodyparts;
1484 for( const std::pair< const bodypart_str_id, int > &elem : occupied_bodyparts ) {
1485 for( const item &i : worn ) {
1486 if( i.covers( elem.first->token ) && !i.has_flag( flag_ALLOWS_NATURAL_ATTACKS ) &&
1487 !i.has_flag( flag_SEMITANGIBLE ) &&
1488 !i.has_flag( flag_PERSONAL ) && !i.has_flag( flag_AURA ) ) {
1489 coverage += i.get_coverage();
1490 }
1491 }
1492 }
1493 effective_efficiency = fuel_efficiency * ( 1.0 - ( coverage / ( 100.0 *
1494 occupied_bodyparts.size() ) )
1495 * coverage_penalty.value() );
1496 }
1497 return effective_efficiency;
1498}
static const std::string flag_SEMITANGIBLE("SEMITANGIBLE")
static const std::string flag_ALLOWS_NATURAL_ATTACKS("ALLOWS_NATURAL_ATTACKS")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
cata::optional< float > coverage_power_gen_penalty
Fraction of coverage diminishing fuel_efficiency.
Definition: bionics.h:71

References b, bionic_data::coverage_power_gen_penalty, flag_ALLOWS_NATURAL_ATTACKS(), flag_AURA(), flag_PERSONAL(), flag_SEMITANGIBLE(), bionic::info(), bionic_data::occupied_bodyparts, cata::optional< T >::value(), and worn.

Referenced by burn_fuel(), and passive_power_gen().

◆ get_encumbrance() [1/2]

char_encumbrance_data Character::get_encumbrance ( ) const

Get encumbrance for all body parts.

Definition at line 3683 of file character.cpp.

3684{
3685 return *encumbrance_cache;
3686}

References encumbrance_cache.

Referenced by item::on_wear(), character_display::print_encumbrance(), and should_combine_bps().

◆ get_encumbrance() [2/2]

char_encumbrance_data Character::get_encumbrance ( const item new_item) const

Get encumbrance for all body parts as if new_item was also worn.

Definition at line 3688 of file character.cpp.

3689{
3690 return calc_encumbrance( new_item );
3691}

References calc_encumbrance().

◆ get_env_resist()

int Character::get_env_resist ( bodypart_id  bp) const
overridevirtual

Returns overall env_resist on a body_part.

Reimplemented from Creature.

Definition at line 7147 of file character.cpp.

7148{
7149 int ret = 0;
7150 for( auto &i : worn ) {
7151 // Head protection works on eyes too (e.g. baseball cap)
7152 if( i.covers( bp->token ) || ( bp == bodypart_id( "eyes" ) && i.covers( bp_head ) ) ) {
7153 ret += i.get_env_resist();
7154 }
7155 }
7156
7157 for( const bionic_id &bid : get_bionics() ) {
7158 const auto EP = bid->env_protec.find( bp.id() );
7159 if( ( !bid->activated || has_active_bionic( bid ) ) && EP != bid->env_protec.end() ) {
7160 ret += EP->second;
7161 }
7162 }
7163
7164 if( bp == bodypart_id( "eyes" ) && has_trait( trait_SEESLEEP ) ) {
7165 ret += 8;
7166 }
7167 return ret;
7168}
static const trait_id trait_SEESLEEP("SEESLEEP")

References bp_head, get_bionics(), has_active_bionic(), has_trait(), int_id< T >::id(), cata::hash64_detail::ret, trait_SEESLEEP, and worn.

Referenced by iexamine::flower_poppy(), is_immune_field(), and map::player_in_field().

◆ get_faction()

virtual faction * Character::get_faction ( ) const
inlinevirtual

Reimplemented in avatar, and npc.

Definition at line 347 of file character.h.

347 {
348 return nullptr;
349 }

Referenced by complete_craft(), npc::consume_food_from_camp(), basecamp::faction_display(), vehicle::handle_potential_theft(), and npc::has_faction_relationship().

◆ get_fastest_sight()

std::pair< int, int > Character::get_fastest_sight ( const item gun,
double  recoil 
) const

Definition at line 577 of file character.cpp.

578{
579 // Get fastest sight that can be used to improve aim further below @ref recoil.
580 int sight_speed_modifier = INT_MIN;
581 int limit = 0;
582 if( effective_dispersion( gun.type->gun->sight_dispersion ) < recoil ) {
583 sight_speed_modifier = gun.has_flag( flag_DISABLE_SIGHTS ) ? 0 : 6;
584 limit = effective_dispersion( gun.type->gun->sight_dispersion );
585 }
586
587 for( const auto e : gun.gunmods() ) {
588 const islot_gunmod &mod = *e->type->gunmod;
589 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
590 continue; // skip gunmods which don't provide a sight
591 }
592 if( effective_dispersion( mod.sight_dispersion ) < recoil &&
593 mod.aim_speed > sight_speed_modifier ) {
594 sight_speed_modifier = mod.aim_speed;
595 limit = effective_dispersion( mod.sight_dispersion );
596 }
597 }
598 return std::make_pair( sight_speed_modifier, limit );
599}
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7572
cata::value_ptr< islot_gun > gun
Definition: itype.h:857

References effective_dispersion(), flag_DISABLE_SIGHTS(), itype::gun, item::gunmods(), item::has_flag(), recoil, and item::type.

Referenced by aim_per_move().

◆ get_fatigue()

◆ get_fatigue_description()

std::pair< std::string, nc_color > Character::get_fatigue_description ( ) const

Definition at line 4412 of file character.cpp.

4413{
4414 int fatigue = get_fatigue();
4415 std::string fatigue_string;
4416 nc_color fatigue_color = c_white;
4418 fatigue_color = c_red;
4419 fatigue_string = _( "Exhausted" );
4420 } else if( fatigue > fatigue_levels::dead_tired ) {
4421 fatigue_color = c_light_red;
4422 fatigue_string = _( "Dead Tired" );
4423 } else if( fatigue > fatigue_levels::tired ) {
4424 fatigue_color = c_yellow;
4425 fatigue_string = _( "Tired" );
4426 }
4427 return std::make_pair( fatigue_string, fatigue_color );
4428}

References _, c_light_red, c_red, c_white, c_yellow, dead_tired, exhausted, fatigue, get_fatigue(), and tired.

Referenced by draw_health_classic(), draw_needs_compact(), draw_needs_labels(), draw_needs_narrow(), spell::energy_cur_string(), npc::faction_display(), and get_consume_needs_hint().

◆ get_free_bionics_slots()

int Character::get_free_bionics_slots ( const bodypart_id bp) const

Definition at line 2527 of file bionics.cpp.

2528{
2530}
int get_total_bionics_slots(const bodypart_id &bp) const
Definition: bionics.cpp:2522
int get_used_bionics_slots(const bodypart_id &bp) const
Definition: bionics.cpp:2494

References get_total_bionics_slots(), and get_used_bionics_slots().

Referenced by bionic_installation_issues(), and player::power_bionics().

◆ get_fuel_available()

std::vector< itype_id > Character::get_fuel_available ( const bionic_id bio) const

Return list of available fuel for this bionic.

Definition at line 2079 of file character.cpp.

2080{
2081 std::vector<itype_id> stored_fuels;
2082 for( const itype_id &fuel : bio->fuel_opts ) {
2083 const item tmp_fuel( fuel );
2084 if( !get_value( fuel.str() ).empty() || tmp_fuel.has_flag( flag_PERPETUAL ) ) {
2085 stored_fuels.emplace_back( fuel );
2086 }
2087 }
2088 return stored_fuels;
2089}
static const std::string flag_PERPETUAL("PERPETUAL")

References flag_PERPETUAL(), bionic_data::fuel_opts, Creature::get_value(), item::has_flag(), and string_id< T >::str().

Referenced by burn_fuel(), draw_bionics_titlebar(), passive_power_gen(), process_bionic(), and npc::recharge_cbm().

◆ get_fuel_capacity()

int Character::get_fuel_capacity ( const itype_id fuel) const

Return available space to store specified fuel.

Definition at line 2091 of file character.cpp.

2092{
2093 int amount_stored = 0;
2094 if( !get_value( fuel.str() ).empty() ) {
2095 amount_stored = std::stoi( get_value( fuel.str() ) );
2096 }
2097 int capacity = 0;
2098 for( const bionic_id &bid : get_bionics() ) {
2099 for( const itype_id &fl : bid->fuel_opts ) {
2100 if( get_value( bid.str() ).empty() || get_value( bid.str() ) == fl.str() ) {
2101 if( fl == fuel ) {
2102 capacity += bid->fuel_capacity;
2103 }
2104 }
2105 }
2106 }
2107 return capacity - amount_stored;
2108}

References get_bionics(), Creature::get_value(), and string_id< T >::str().

Referenced by fuel_bionic_with().

◆ get_fueled_bionics()

std::vector< bionic_id > Character::get_fueled_bionics ( ) const

Return bionic_id of fueled bionics.

Definition at line 1946 of file character.cpp.

1947{
1948 std::vector<bionic_id> bionics;
1949 for( const bionic_id &bid : get_bionics() ) {
1950 if( !bid->fuel_opts.empty() ) {
1951 bionics.emplace_back( bid );
1952 }
1953 }
1954 return bionics;
1955}

References get_bionics().

Referenced by npc::recharge_cbm(), and npc::wants_to_recharge_cbm().

◆ get_grammatical_genders()

std::vector< std::string > Character::get_grammatical_genders ( ) const
overridevirtual

Reimplemented from Creature.

Definition at line 6115 of file character.cpp.

6116{
6117 if( male ) {
6118 return { "m" };
6119 } else {
6120 return { "f" };
6121 }
6122}

References male.

Referenced by translate_gendered_line().

◆ get_healthy()

int Character::get_healthy ( ) const
virtual

◆ get_healthy_mod()

int Character::get_healthy_mod ( ) const
virtual

Definition at line 4161 of file character.cpp.

4162{
4163 return healthy_mod;
4164}

References healthy_mod.

Referenced by debug_menu::character_edit_menu(), player::process_one_effect(), suffer_from_radiation(), update_health(), and vomit().

◆ get_highest_category()

std::string Character::get_highest_category ( ) const

Returns the highest mutation category.

Returns the mutation category with the highest strength.

Definition at line 7984 of file character.cpp.

7985{
7986 int iLevel = 0;
7987 std::string sMaxCat;
7988
7989 for( const std::pair<const std::string, int> &elem : mutation_category_level ) {
7990 if( elem.second > iLevel ) {
7991 sMaxCat = elem.first;
7992 iLevel = elem.second;
7993 } else if( elem.second == iLevel ) {
7994 sMaxCat.clear(); // no category on ties
7995 }
7996 }
7997 return sMaxCat;
7998}
std::map< std::string, int > mutation_category_level
Definition: character.h:1729

References mutation_category_level.

Referenced by player::hardcoded_effects(), old_mutate(), map::player_in_field(), and test_crossing_threshold().

◆ get_hit_base()

float Character::get_hit_base ( ) const
overridevirtual
Dexterity increases hit base, slightly

Implements Creature.

Definition at line 5857 of file character.cpp.

5858{
5859 /** @EFFECT_DEX increases hit base, slightly */
5860 return get_dex() / 4.0f;
5861}

References get_dex().

Referenced by get_melee_hit_base().

◆ get_hit_weapon()

float Character::get_hit_weapon ( const item weap) const

Gets melee accuracy component from weapon+skills.

Unarmed improves hit chance for unarmed weapons Bashing improves hit chance for bashing weapons Cutting improves hit chance for cutting weapons Stabbing improves hit chance for piercing weapons Melee improves hit chance for all items (including non-weapons)

Definition at line 274 of file melee.cpp.

275{
276 /** @EFFECT_UNARMED improves hit chance for unarmed weapons */
277 /** @EFFECT_BASHING improves hit chance for bashing weapons */
278 /** @EFFECT_CUTTING improves hit chance for cutting weapons */
279 /** @EFFECT_STABBING improves hit chance for piercing weapons */
280 auto skill = get_skill_level( weap.melee_skill() );
281
282 // CQB bionic acts as a lower bound providing item uses a weapon skill
283 if( skill < BIO_CQB_LEVEL && has_active_bionic( bio_cqb ) ) {
284 skill = BIO_CQB_LEVEL;
285 }
286
287 /** @EFFECT_MELEE improves hit chance for all items (including non-weapons) */
288 return ( skill / 3.0f ) + ( get_skill_level( skill_melee ) / 2.0f ) + weap.type->m_to_hit;
289}

References bio_cqb, BIO_CQB_LEVEL, get_skill_level(), has_active_bionic(), itype::m_to_hit, item::melee_skill(), skill_melee, and item::type.

Referenced by item::effective_dps(), and get_melee_hit_base().

◆ get_hostile_creatures()

std::vector< Creature * > Character::get_hostile_creatures ( int  range) const

Get all hostile creatures currently visible to this player.

Definition at line 10244 of file character.cpp.

10245{
10246 return g->get_creatures_if( [this, range]( const Creature & critter ) -> bool {
10247 // Fixes circular distance range for ranged attacks
10248 float dist_to_creature = std::round( rl_dist_exact( pos(), critter.pos() ) );
10249 return this != &critter && pos() != critter.pos() && // TODO: get rid of fake npcs (pos() check)
10250 dist_to_creature <= range && critter.attitude_to( *this ) == A_HOSTILE
10251 && sees( critter );
10252 } );
10253}
virtual Attitude attitude_to(const Creature &other) const =0
Attitude (of this creature) towards another creature.
float rl_dist_exact(const tripoint &loc1, const tripoint &loc2)
Definition: line.cpp:292

References Creature::A_HOSTILE, Creature::attitude_to(), g, Creature::pos(), pos(), rl_dist_exact(), and sees().

◆ get_hunger_description()

std::pair< std::string, nc_color > Character::get_hunger_description ( ) const

Definition at line 4377 of file character.cpp.

4378{
4379 int total_kcal = stored_calories + stomach.get_calories();
4380 int max_kcal = max_stored_kcal();
4381 float days_left = static_cast<float>( total_kcal ) / bmr();
4382 float days_max = static_cast<float>( max_kcal ) / bmr();
4383 std::string hunger_string;
4384 nc_color hunger_color = c_white;
4385 if( days_left >= days_max ) {
4386 hunger_string = _( "Engorged" );
4387 hunger_color = c_green;
4388 } else if( days_max - days_left < 0.5f ) {
4389 hunger_string = _( "Sated" );
4390 hunger_color = c_green;
4391 } else if( days_max - days_left < 1.0f ) {
4392 hunger_string = _( "Hungry" );
4393 hunger_color = c_yellow;
4394 } else if( days_max / days_left < 2.0f ) {
4395 hunger_string = _( "Very Hungry" );
4396 hunger_color = c_yellow;
4397 } else if( days_left > 1 ) {
4398 hunger_string = _( "Famished" );
4399 hunger_color = c_light_red;
4400 } else {
4401 hunger_string = _( "Starving" );
4402 hunger_color = c_red;
4403 }
4404
4405 if( has_trait( trait_SELFAWARE ) ) {
4406 hunger_string = string_format( "%d kcal", total_kcal );
4407 }
4408
4409 return std::make_pair( hunger_string, hunger_color );
4410}
static const trait_id trait_SELFAWARE("SELFAWARE")

References _, bmr(), c_green, c_light_red, c_red, c_white, c_yellow, stomach_contents::get_calories(), has_trait(), max_stored_kcal(), stomach, stored_calories, string_format(), and trait_SELFAWARE.

Referenced by draw_health_classic(), draw_needs_compact(), draw_needs_labels(), draw_needs_narrow(), npc::faction_display(), and get_consume_needs_hint().

◆ get_int()

◆ get_int_base()

int Character::get_int_base ( ) const
virtual

Reimplemented in avatar.

Definition at line 4109 of file character.cpp.

4110{
4111 return int_max;
4112}

References int_max.

Referenced by enchantment::activate_passive(), draw_stats_tab(), get_int(), and avatar::get_int_base().

◆ get_int_bonus()

int Character::get_int_bonus ( ) const
virtual

Definition at line 4126 of file character.cpp.

4127{
4128 return int_bonus;
4129}

References int_bonus.

Referenced by reset_stats().

◆ get_item_position()

int Character::get_item_position ( const item it) const

Returns the item position (suitable for i_at or similar) of a specific item.

Returns INT_MIN if the item is not found. Note that this may lose some information, for example the returned position is the same when the given item points to the container and when it points to the item inside the container. All items that are part of the same stack have the same item position.

Definition at line 2410 of file character.cpp.

2411{
2412 if( weapon.has_item( *it ) ) {
2413 return -1;
2414 }
2415
2416 int p = 0;
2417 for( const auto &e : worn ) {
2418 if( e.has_item( *it ) ) {
2419 return worn_position_to_index( p );
2420 }
2421 p++;
2422 }
2423
2424 return inv.position_by_item( it );
2425}
static int worn_position_to_index(int position)
Definition: character.h:1079
int position_by_item(const item *it) const
Returns the item position of the stack that contains the given item (compared by pointers).
Definition: inventory.cpp:826
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:95

References visitable< T >::has_item(), inv, inventory::position_by_item(), weapon, worn, and worn_position_to_index().

Referenced by npc::alt_attack(), game::butcher(), iuse::chop_logs(), iuse::chop_tree(), chop_tree_activity(), convert_to_items(), damage_item(), iuse::fill_pit(), iuse::hacksaw(), iexamine::locked_object_pickable(), iuse::makemound(), item_location::impl::item_on_person::obtain(), iuse::pack_item(), iuse::play_game(), iuse::radglove(), iuse::stimpack(), salvage_actor::try_to_cut_up(), pick_lock_actor::use(), musical_instrument_actor::use(), repair_item_actor::use(), sew_advanced_actor::use(), and game::wield().

◆ get_kcal_percent()

◆ get_lowest_hp()

int Character::get_lowest_hp ( ) const

Definition at line 10367 of file character.cpp.

10368{
10369 // Set lowest_hp to an arbitrarily large number.
10370 int lowest_hp = 999;
10371 for( const std::pair<const bodypart_str_id, bodypart> &elem : get_body() ) {
10372 const int cur_hp = elem.second.get_hp_cur();
10373 if( cur_hp < lowest_hp ) {
10374 lowest_hp = cur_hp;
10375 }
10376 }
10377 return lowest_hp;
10378}

References Creature::get_body().

Referenced by debug_menu::character_edit_menu().

◆ get_max_healthy()

int Character::get_max_healthy ( ) const

Definition at line 4559 of file character.cpp.

4560{
4561 return 200;
4562}

Referenced by update_health().

◆ get_max_power_level()

◆ get_melee_hit_base()

float Character::get_melee_hit_base ( ) const

Returns weapon skill.

Definition at line 291 of file melee.cpp.

292{
293 // Character::get_hit_base includes stat calculations already
295}
const item & used_weapon() const
Returns a reference to the item which will be used to make attacks.
Definition: melee.cpp:135
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:274
float get_hit_base() const override
Definition: character.cpp:5857
float mabuff_tohit_bonus() const
Returns the to hit bonus from martial arts buffs.

References get_hit_base(), get_hit_weapon(), mabuff_tohit_bonus(), and used_weapon().

Referenced by draw_stats_info(), hit_roll(), and set_stats().

◆ get_miss_reason()

std::string Character::get_miss_reason ( )

Returns an explanation for why the player would miss a melee attack.

Definition at line 329 of file melee.cpp.

330{
331 // everything that lowers accuracy in player::hit_roll()
332 // adding it in hit_roll() might not be safe if it's called multiple times
333 // in one turn
335 _( "Your torso encumbrance throws you off-balance." ),
336 roll_remainder( encumb( bp_torso ) / 10.0 ) );
337 const int farsightedness = 2 * ( has_trait( trait_HYPEROPIC ) &&
338 !worn_with_flag( "FIX_FARSIGHT" ) &&
341 _( "You can't hit reliably due to your farsightedness." ),
342 farsightedness );
343
344 const std::string *const reason = melee_miss_reasons.pick();
345 if( reason == nullptr ) {
346 return std::string();
347 }
348 return *reason;
349}
void add_miss_reason(const std::string &reason, unsigned int weight)
Adds a reason for why the player would miss a melee attack.
Definition: melee.cpp:318
static const efftype_id effect_contacts("contacts")
static const trait_id trait_HYPEROPIC("HYPEROPIC")

References _, add_miss_reason(), bp_torso, effect_contacts, encumb(), Creature::has_effect(), has_trait(), melee_miss_reasons, roll_remainder(), trait_HYPEROPIC, and worn_with_flag().

Referenced by melee_attack().

◆ get_mod()

int Character::get_mod ( const trait_id mut,
const std::string &  arg 
) const
private

Retrieves a stat mod of a mutation.

Definition at line 195 of file mutation.cpp.

196{
197 auto &mod_data = mut->mods;
198 int ret = 0;
199 auto found = mod_data.find( std::make_pair( false, arg ) );
200 if( found != mod_data.end() ) {
201 ret += found->second;
202 }
203 return ret;
204}
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
\rst Returns a named argument to be used in a formatting function.
Definition: fmtlib_core.h:1860
std::unordered_map< std::pair< bool, std::string >, int, cata::tuple_hash > mods
Key pair is <active: bool, mod type: "STR">
Definition: mutation.h:273

References arg(), mutation_branch::mods, and cata::hash64_detail::ret.

Referenced by apply_mods().

◆ get_mod_stat_from_bionic()

int Character::get_mod_stat_from_bionic ( const character_stat Stat) const

Get stat bonus from bionic.

Definition at line 2172 of file character.cpp.

2173{
2174 int ret = 0;
2175 for( const bionic_id &bid : get_bionics() ) {
2176 const auto St_bn = bid->stat_bonus.find( Stat );
2177 if( St_bn != bid->stat_bonus.end() ) {
2178 ret += St_bn->second;
2179 }
2180 }
2181 return ret;
2182}

References get_bionics(), and cata::hash64_detail::ret.

Referenced by reset_stats().

◆ get_morale()

int Character::get_morale ( const morale_type type) const

Definition at line 9121 of file character.cpp.

9122{
9123 return morale->get( type );
9124}

References morale, and type.

◆ get_morale_level()

int Character::get_morale_level ( ) const

◆ get_most_accurate_sight()

int Character::get_most_accurate_sight ( const item gun) const

Definition at line 601 of file character.cpp.

602{
603 if( !gun.is_gun() ) {
604 return 0;
605 }
606
607 int limit = effective_dispersion( gun.type->gun->sight_dispersion );
608 for( const auto e : gun.gunmods() ) {
609 const islot_gunmod &mod = *e->type->gunmod;
610 if( mod.aim_speed >= 0 ) {
611 limit = std::min( limit, effective_dispersion( mod.sight_dispersion ) );
612 }
613 }
614
615 return limit;
616}

References effective_dispersion(), itype::gun, item::gunmods(), item::is_gun(), and item::type.

Referenced by npc::invalidate_range_cache(), and npc::method_of_attack().

◆ get_most_efficient_bionic()

bionic_id Character::get_most_efficient_bionic ( const std::vector< bionic_id > &  bids) const

Return bionic_id of bionic of most fuel efficient bionic.

Definition at line 1957 of file character.cpp.

1958{
1959 float temp_eff = 0;
1960 bionic_id bio( "null" );
1961 for( const bionic_id &bid : bids ) {
1962 if( bid->fuel_efficiency > temp_eff ) {
1963 temp_eff = bid->fuel_efficiency;
1964 bio = bid;
1965 }
1966 }
1967 return bio;
1968}

Referenced by fuel_bionic_with(), and get_acquirable_energy().

◆ get_movement_mode()

character_movemode Character::get_movement_mode ( ) const

Definition at line 1617 of file character.cpp.

1618{
1619 return move_mode;
1620}

References move_mode.

Referenced by cata_event_dispatch::avatar_moves().

◆ get_mutation_social_mods()

social_modifiers Character::get_mutation_social_mods ( ) const

Goes over all mutations, returning the sum of the social modifiers.

Definition at line 6683 of file character.cpp.

6684{
6685 social_modifiers mods;
6686 for( const mutation_branch *mut : cached_mutations ) {
6687 mods += mut->social_mods;
6688 }
6689
6690 return mods;
6691}

References cached_mutations.

Referenced by talk_trial::calc_chance().

◆ get_mutations()

std::vector< trait_id > Character::get_mutations ( bool  include_hidden = true) const

Get the idents of all traits/mutations.

Definition at line 2815 of file newcharacter.cpp.

2816{
2817 std::vector<trait_id> result;
2818 for( const std::pair<const trait_id, trait_data> &t : my_mutations ) {
2819 if( include_hidden || t.first.obj().player_display ) {
2820 result.push_back( t.first );
2821 }
2822 }
2823 for( const trait_id &ench_trait : enchantment_cache->get_mutations() ) {
2824 if( include_hidden || ench_trait->player_display ) {
2825 bool found = false;
2826 for( const trait_id &exist : result ) {
2827 if( exist == ench_trait ) {
2828 found = true;
2829 break;
2830 }
2831 }
2832 if( !found ) {
2833 result.push_back( ench_trait );
2834 }
2835 }
2836 }
2837 return result;
2838}

References enchantment_cache, and my_mutations.

Referenced by monster::attitude(), bodytemp_modifier_traits(), bodytemp_modifier_traits_floor(), can_eat(), can_install_cbm_on_bp(), can_use_heal_item(), can_wear(), check_and_recover_morale(), compute_default_effective_vitamins(), player::crafting_success_roll(), avatar::create(), crossed_threshold(), character_display::disp_info(), drench_mut_calc(), npc::form_opinion(), has_trait_flag(), is_category_allowed(), is_weak_to_water(), mod_healthy(), mut_cbm_encumb(), mutation_armor(), mutation_attacks(), item::mutations_from_wearing(), player::process_turn(), avatar::randomize(), reset_scenario(), roll_bash_damage(), roll_cut_damage(), roll_stab_damage(), set_description(), set_highest_cat_level(), set_profession(), sleep(), update_type_of_scent(), visible_mutations(), vitamin_rate(), and memorial_logger::write().

◆ get_name()

std::string Character::get_name ( ) const
overridevirtual

Implements Creature.

Definition at line 6110 of file character.cpp.

6111{
6112 return name;
6113}

References name.

Referenced by autodoc_internal(), debug_menu::character_edit_menu(), npc::die(), pour_into(), npc::set_omt_destination(), and game::vertical_move().

◆ get_next_auto_move_direction()

action_id Character::get_next_auto_move_direction ( )

Definition at line 10530 of file character.cpp.

10531{
10532 if( !has_destination() ) {
10533 return ACTION_NULL;
10534 }
10535
10537 if( pos() != *next_expected_position ) {
10538 // We're off course, possibly stumbling or stuck, cancel auto move
10539 return ACTION_NULL;
10540 }
10541 }
10542
10543 next_expected_position.emplace( auto_move_route.front() );
10544 auto_move_route.erase( auto_move_route.begin() );
10545
10547
10548 // Make sure the direction is just one step and that
10549 // all diagonal moves have 0 z component
10550 if( std::abs( dp.x ) > 1 || std::abs( dp.y ) > 1 || std::abs( dp.z ) > 1 ||
10551 ( std::abs( dp.z ) != 0 && ( std::abs( dp.x ) != 0 || std::abs( dp.y ) != 0 ) ) ) {
10552 // Should never happen, but check just in case
10553 return ACTION_NULL;
10554 }
10556}
action_id get_movement_action_from_delta(const tripoint &d, const iso_rotate rot)
Translate coordinate delta into movement action.
Definition: action.cpp:478
@ ACTION_NULL
Invalid action used for various lookup errors.
Definition: action.h:24
int y
Definition: point.h:151
int z
Definition: point.h:152
int x
Definition: point.h:150

References ACTION_NULL, auto_move_route, get_movement_action_from_delta(), has_destination(), next_expected_position, pos(), tripoint::x, tripoint::y, yes, and tripoint::z.

Referenced by game::handle_action(), and game::try_get_left_click_action().

◆ get_overlay_ids()

std::vector< std::string > Character::get_overlay_ids ( ) const

Returns a list of the IDs of overlays on this character, sorted from "lowest" to "highest".

Only required for rendering.

Definition at line 3294 of file character.cpp.

3295{
3296 std::vector<std::string> rval;
3297 std::multimap<int, std::string> mutation_sorting;
3298 int order;
3299 std::string overlay_id;
3300
3301 // first get effects
3302 for( const auto &eff_pr : *effects ) {
3303 if( !eff_pr.second.begin()->second.is_removed() ) {
3304 rval.push_back( "effect_" + eff_pr.first.str() );
3305 }
3306 }
3307
3308 // then get mutations
3309 for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
3310 overlay_id = ( mut.second.powered ? "active_" : "" ) + mut.first.str();
3311 order = get_overlay_order_of_mutation( overlay_id );
3312 mutation_sorting.insert( std::pair<int, std::string>( order, overlay_id ) );
3313 }
3314
3315 // then get bionics
3316 for( const bionic &bio : *my_bionics ) {
3317 overlay_id = ( bio.powered ? "active_" : "" ) + bio.id.str();
3318 order = get_overlay_order_of_mutation( overlay_id );
3319 mutation_sorting.insert( std::pair<int, std::string>( order, overlay_id ) );
3320 }
3321
3322 for( auto &mutorder : mutation_sorting ) {
3323 rval.push_back( "mutation_" + mutorder.second );
3324 }
3325
3326 // next clothing
3327 // TODO: worry about correct order of clothing overlays
3328 for( const item &worn_item : worn ) {
3329 rval.push_back( "worn_" + worn_item.typeId().str() );
3330 }
3331
3332 // last weapon
3333 // TODO: might there be clothing that covers the weapon?
3334 if( is_armed() ) {
3335 rval.push_back( "wielded_" + weapon.typeId().str() );
3336 }
3337
3338 if( move_mode != CMM_WALK ) {
3339 rval.push_back( io::enum_to_string( move_mode ) );
3340 }
3341 return rval;
3342}
bool is_armed() const
Returns true if the character is wielding something.
Definition: melee.cpp:145
std::string enum_to_string(E)
int get_overlay_order_of_mutation(const std::string &mutation_id_string)

References CMM_WALK, Creature::effects, io::enum_to_string(), get_overlay_order_of_mutation(), is_armed(), move_mode, my_bionics, my_mutations, string_id< T >::str(), item::typeId(), weapon, and worn.

◆ get_pain_description()

std::pair< std::string, nc_color > Character::get_pain_description ( ) const
overridevirtual

Reimplemented from Creature.

Definition at line 4481 of file character.cpp.

4482{
4483 const std::pair<std::string, nc_color> pain = Creature::get_pain_description();
4484 nc_color pain_color = pain.second;
4485 std::string pain_string;
4486 // get pain color
4487 if( get_perceived_pain() >= 60 ) {
4488 pain_color = c_red;
4489 } else if( get_perceived_pain() >= 40 ) {
4490 pain_color = c_light_red;
4491 }
4492 // get pain string
4494 get_perceived_pain() > 0 ) {
4495 pain_string = string_format( "%s %d", _( "Pain " ), get_perceived_pain() );
4496 } else if( get_perceived_pain() > 0 ) {
4497 pain_string = pain.first;
4498 }
4499 return std::make_pair( pain_string, pain_color );
4500}
static const efftype_id effect_got_checked("got_checked")
virtual std::pair< std::string, nc_color > get_pain_description() const
Definition: creature.cpp:1376
int pain
Definition: creature.h:888

References _, c_light_red, c_red, effect_got_checked, Creature::get_pain_description(), Creature::get_perceived_pain(), Creature::has_effect(), has_trait(), Creature::pain, string_format(), and trait_SELFAWARE.

Referenced by draw_health_classic(), draw_needs_compact(), draw_needs_labels(), draw_needs_narrow(), and get_consume_needs_hint().

◆ get_painkiller()

◆ get_path_avoid()

std::set< tripoint > Character::get_path_avoid ( ) const
overridevirtual

Returns a set of points we do not want to path through.

Implements Creature.

Reimplemented in npc.

Definition at line 9960 of file character.cpp.

9961{
9962 std::set<tripoint> ret;
9963 for( npc &guy : g->all_npcs() ) {
9964 if( sees( guy ) ) {
9965 ret.insert( guy.pos() );
9966 }
9967 }
9968
9969 // TODO: Add known traps in a way that doesn't destroy performance
9970
9971 return ret;
9972}

References g, cata::hash64_detail::ret, and sees().

Referenced by activity_on_turn_move_loot(), can_mount(), game::handle_action(), game::list_items(), game::look_around(), perform_zone_activity_turn(), route_adjacent(), activity_handlers::travel_do_turn(), and game::try_get_left_click_action().

◆ get_pathfinding_settings()

const pathfinding_settings & Character::get_pathfinding_settings ( ) const
overridevirtual

◆ get_per()

◆ get_per_base()

int Character::get_per_base ( ) const
virtual

Reimplemented in avatar.

Definition at line 4105 of file character.cpp.

4106{
4107 return per_max;
4108}

References per_max.

Referenced by enchantment::activate_passive(), draw_stats_tab(), get_per(), and avatar::get_per_base().

◆ get_per_bonus()

int Character::get_per_bonus ( ) const
virtual

Definition at line 4122 of file character.cpp.

4123{
4124 return per_bonus;
4125}

References per_bonus.

Referenced by reset_stats().

◆ get_power_level()

◆ get_rad()

◆ get_remote_fueled_bionic()

bionic_id Character::get_remote_fueled_bionic ( ) const

Returns bionic_id of first remote fueled bionic found.

Definition at line 1905 of file character.cpp.

1906{
1907 for( const bionic_id &bid : get_bionics() ) {
1908 if( bid->is_remote_fueled ) {
1909 return bid;
1910 }
1911 }
1912 return bionic_id();
1913}

References bionic_id, and get_bionics().

Referenced by iuse::cable_attach(), and iuse::solarpack().

◆ get_shout_volume()

int Character::get_shout_volume ( ) const
Strength increases shouting volume

Definition at line 7700 of file character.cpp.

7701{
7702 int base = 10;
7703 int shout_multiplier = 2;
7704
7705 // Mutations make shouting louder, they also define the default message
7706 if( has_trait( trait_SHOUT3 ) ) {
7707 shout_multiplier = 4;
7708 base = 20;
7709 } else if( has_trait( trait_SHOUT2 ) ) {
7710 base = 15;
7711 shout_multiplier = 3;
7712 }
7713
7714 // You can't shout without your face
7715 if( has_trait( trait_PROF_FOODP ) && !( is_wearing( itype_id( "foodperson_mask" ) ) ||
7716 is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
7717 base = 0;
7718 shout_multiplier = 0;
7719 }
7720
7721 // Masks and such dampen the sound
7722 // Balanced around whisper for wearing bondage mask
7723 // and noise ~= 10 (door smashing) for wearing dust mask for character with strength = 8
7724 /** @EFFECT_STR increases shouting volume */
7725 const int penalty = encumb( bp_mouth ) * 3 / 2;
7726 int noise = base + str_cur * shout_multiplier - penalty;
7727
7728 // Minimum noise volume possible after all reductions.
7729 // Volume 1 can't be heard even by player
7730 constexpr int minimum_noise = 2;
7731
7732 if( noise <= base ) {
7733 noise = std::max( minimum_noise, noise );
7734 }
7735
7736 // Screaming underwater is not good for oxygen and harder to do overall
7737 if( underwater ) {
7738 noise = std::max( minimum_noise, noise / 2 );
7739 }
7740 return noise;
7741}
static const trait_id trait_SHOUT2("SHOUT2")
static const trait_id trait_SHOUT3("SHOUT3")
bool underwater
Definition: creature.h:570

References bp_mouth, encumb(), has_trait(), is_wearing(), itype_id, noise, str_cur, trait_PROF_FOODP, trait_SHOUT2, trait_SHOUT3, and Creature::underwater.

Referenced by npc::say(), shout(), and activity_handlers::spellcasting_finish().

◆ get_size()

◆ get_skill_level() [1/2]

int Character::get_skill_level ( const skill_id ident) const

Definition at line 3359 of file character.cpp.

3360{
3361 return _skills->get_skill_level( ident );
3362}

References _skills.

Referenced by npc::address_needs(), aim_speed_skill_modifier(), apply_skill_boost(), iexamine::arcfurnace_empty(), attack_cost(), player::avoid_trap(), mattack::bio_op_disarm(), bionics_pl_skill(), block_hit(), ranged::burst_penalty(), activity_handlers::butcher_finish(), calc_skill_training_time(), veh_utils::calc_xp_gain(), character_martial_arts::can_arm_block(), player::can_autolearn(), can_estimate_rot(), character_martial_arts::can_leg_block(), can_mount(), npc::can_read(), enzlave_actor::can_use(), caravan_price(), activity_handlers::chop_planks_finish(), item::color_in_inventory(), companion_combat_rank(), companion_industry_rank(), companion_survival_rank(), complete_craft(), player::complete_disassemble(), player::crafting_success_roll(), crit_chance(), iuse::crowbar(), salvage_actor::cut_up(), mattack::dermatik(), trap::detect_trap(), player::disarm(), avatar::do_read(), dialogue::dynamic_line(), iuse::einktabletpc(), enumerate_unmet_requirements(), spell::exp_modifier(), map_data_common_t::extended_description(), npc::faction_display(), player::fall_damage_mod(), farm_action(), game::find_or_make_stairs(), npc::finish_read(), activity_handlers::fish_do_turn(), iuse::fish_trap(), fungal_effects::fungalize(), player::get_available_recipes(), item::get_available_recipes(), heal_actor::get_bandaged_level(), avatar::get_book_reader(), heal_actor::get_disinfected_level(), get_dodge_base(), get_encumbrance_description(), heal_actor::get_heal_value(), get_hit_weapon(), player::get_melee(), player_activity::get_progress_message(), player::get_weapon_dispersion(), iuse::gun_repair(), player::gun_value(), player::gunmod_installation_odds(), computer_session::hack_attempt(), hack_level(), hackveh(), handle_melee_wear(), hardcoded_mutation_attack(), harvest_common(), iexamine::harvest_plant(), has_skill_for_vehicle_work(), ma_requirements::is_valid_character(), player::item_reload_cost(), item_store_cost(), ma_style_callback::key(), iexamine::kiln_empty(), activity_handlers::lockpicking_finish(), melee_attack(), player::mend_item(), iuse::mind_splicer(), player::morale_crafting_speed_multiplier(), iuse::multicooker(), mutation_attacks(), npc_trading::net_price_adjustment(), game::npc_menu(), player::on_dodge(), item::on_wield(), iuse::pack_cbm(), pick_part_to_heal(), pick_plant(), vehicle::pldrive(), player::practice(), iexamine::practice_survival_while_foraging(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), avatar::randomize(), player::rate_action_use(), player::reach_attack(), avatar::read(), recalc_hp(), repair_item_actor::repair(), repair_item_actor::repair_chance(), activity_handlers::repair_item_finish(), activity_handlers::robot_control_finish(), iuse::robotcontrol(), roll_bash_damage(), roll_cut_damage(), roll_stab_damage(), iexamine::safe(), scavenging_combat_skill(), set_description(), conditional_t< T >::set_has_skill(), set_skills(), map::shake_vehicle(), iexamine::shrub_wildveggies(), sinkhole_safety_roll(), skill_increment_cost(), npc::skills_offered_to(), smash(), read_inventory_preset::sort_compare(), spell::spell_fail(), player::start_craft(), talk_function::start_training(), suffer_from_schizophrenia(), survive_random_encounter(), swim_speed(), player::talk_skill(), iuse::tazer(), player::throw_item(), throw_range(), mattack::thrown_by_judo(), time_to_attack(), known_magic::time_to_learn_spell(), npc::time_to_read(), avatar::time_to_read(), activity_handlers::train_finish(), iexamine::tree_hickory(), place_monster_iuse::use(), firestarter_actor::use(), enzlave_actor::use(), heal_actor::use(), sew_advanced_actor::use(), npc::value(), game::vertical_move(), player::wield_contents(), and debug_menu::wishskill().

◆ get_skill_level() [2/2]

int Character::get_skill_level ( const skill_id ident,
const item context 
) const

Definition at line 3364 of file character.cpp.

3365{
3366 return _skills->get_skill_level( ident, context );
3367}

References _skills.

◆ get_skill_level_object() [1/2]

◆ get_skill_level_object() [2/2]

const SkillLevel & Character::get_skill_level_object ( const skill_id ident) const

Definition at line 3349 of file character.cpp.

3350{
3351 return _skills->get_skill_level_object( ident );
3352}

References _skills.

◆ get_sleep_deprivation()

int Character::get_sleep_deprivation ( ) const

◆ get_speed()

◆ get_stamina()

◆ get_stamina_max()

int Character::get_stamina_max ( ) const

◆ get_stashed_activity()

player_activity Character::get_stashed_activity ( ) const

Definition at line 973 of file character.cpp.

974{
976}

References stashed_outbounds_activity.

Referenced by npc::move().

◆ get_stim()

◆ get_stored_kcal()

◆ get_str()

◆ get_str_base()

int Character::get_str_base ( ) const
virtual

Reimplemented in avatar.

Definition at line 4097 of file character.cpp.

4098{
4099 return str_max;
4100}

References str_max.

Referenced by enchantment::activate_passive(), draw_stats_tab(), get_str(), and avatar::get_str_base().

◆ get_str_bonus()

int Character::get_str_bonus ( ) const
virtual

Definition at line 4114 of file character.cpp.

4115{
4116 return str_bonus;
4117}

References str_bonus.

Referenced by reset_stats().

◆ get_thirst()

◆ get_thirst_description()

std::pair< std::string, nc_color > Character::get_thirst_description ( ) const

Definition at line 4348 of file character.cpp.

4349{
4350 int thirst = get_thirst();
4351 std::string hydration_string;
4352 nc_color hydration_color = c_white;
4354 hydration_color = c_light_red;
4355 hydration_string = _( "Parched" );
4356 } else if( thirst > thirst_levels::dehydrated ) {
4357 hydration_color = c_light_red;
4358 hydration_string = _( "Dehydrated" );
4359 } else if( thirst > thirst_levels::very_thirsty ) {
4360 hydration_color = c_yellow;
4361 hydration_string = _( "Very thirsty" );
4362 } else if( thirst > thirst_levels::thirsty ) {
4363 hydration_color = c_yellow;
4364 hydration_string = _( "Thirsty" );
4365 } else if( thirst > thirst_levels::slaked ) {
4366 // Nothing
4367 } else if( thirst > thirst_levels::hydrated ) {
4368 hydration_color = c_green;
4369 hydration_string = _( "Hydrated" );
4370 } else if( thirst > thirst_levels::turgid ) {
4371 hydration_color = c_green;
4372 hydration_string = _( "Turgid" );
4373 }
4374 return std::make_pair( hydration_string, hydration_color );
4375}

References _, c_green, c_light_red, c_white, c_yellow, dehydrated, get_thirst(), hydrated, parched, slaked, thirst, thirsty, turgid, and very_thirsty.

Referenced by draw_health_classic(), draw_needs_compact(), draw_needs_labels(), draw_needs_narrow(), npc::faction_display(), and get_consume_needs_hint().

◆ get_time_died()

time_point Character::get_time_died ( ) const
inline

return the calendar::turn the character expired

Definition at line 1410 of file character.h.

1410 {
1411 return time_died;
1412 }
time_point time_died
Definition: character.h:2115

References time_died.

◆ get_total_bionics_slots()

int Character::get_total_bionics_slots ( const bodypart_id bp) const

Definition at line 2522 of file bionics.cpp.

2523{
2524 return bp->bionic_slots();
2525}

Referenced by get_free_bionics_slots(), and player::power_bionics().

◆ get_total_fuel_capacity()

int Character::get_total_fuel_capacity ( const itype_id fuel) const

Return total space to store specified fuel.

Definition at line 2110 of file character.cpp.

2111{
2112 int capacity = 0;
2113 for( const bionic_id &bid : get_bionics() ) {
2114 for( const itype_id &fl : bid->fuel_opts ) {
2115 if( get_value( bid.str() ).empty() || get_value( bid.str() ) == fl.str() ) {
2116 if( fl == fuel ) {
2117 capacity += bid->fuel_capacity;
2118 }
2119 }
2120 }
2121 }
2122 return capacity;
2123}

References get_bionics(), Creature::get_value(), and string_id< T >::str().

Referenced by draw_bionics_titlebar().

◆ get_type_of_scent()

scenttype_id Character::get_type_of_scent ( ) const

Definition at line 8773 of file character.cpp.

8774{
8775 return type_of_scent;
8776}
scenttype_id type_of_scent
Definition: character.h:2197

References type_of_scent.

Referenced by game::do_turn(), update_type_of_scent(), and change_scent_iuse::use().

◆ get_used_bionics_slots()

int Character::get_used_bionics_slots ( const bodypart_id bp) const

Definition at line 2494 of file bionics.cpp.

2495{
2496 int used_slots = 0;
2497 for( const bionic_id &bid : get_bionics() ) {
2498 auto search = bid->occupied_bodyparts.find( bp.id() );
2499 if( search != bid->occupied_bodyparts.end() ) {
2500 used_slots += search->second;
2501 }
2502 }
2503
2504 return used_slots;
2505}
static bool search(const ui_adaptor &om_ui, tripoint_abs_omt &curs, const tripoint_abs_omt &orig)

References get_bionics(), int_id< T >::id(), and overmap_ui::search().

Referenced by get_free_bionics_slots().

◆ get_visible_creatures()

std::vector< Creature * > Character::get_visible_creatures ( int  range) const

Returns all creatures that this player can see and that are in the given range.

This player object itself is never included. The player character (g->u) is checked and might be included (if applicable).

Parameters
rangeThe maximal distance (rl_dist), creatures at this distance or less are included.

Definition at line 10236 of file character.cpp.

10237{
10238 return g->get_creatures_if( [this, range]( const Creature & critter ) -> bool {
10239 return this != &critter && pos() != critter.pos() && // TODO: get rid of fake npcs (pos() check)
10240 rl_dist( pos(), critter.pos() ) <= range && sees( critter );
10241 } );
10242}

References g, Creature::pos(), pos(), rl_dist(), and sees().

Referenced by game::is_hostile_within(), game::list_items_monsters(), and game::mon_info_update().

◆ get_vision_modes()

const std::bitset< NUM_VISION_MODES > & Character::get_vision_modes ( ) const
inline

Definition at line 1495 of file character.h.

1495 {
1496 return vision_mode_cache;
1497 }

References vision_mode_cache.

◆ get_vision_threshold()

float Character::get_vision_threshold ( float  light_level) const

Returns the apparent light level at which the player can see.

This is adjusted by the light level at the character's position to simulate glare, etc, night vision only works if you are in the dark.

Definition at line 1812 of file character.cpp.

1813{
1815 // Debug vision always works with absurdly little light.
1816 return 0.01;
1817 }
1818
1819 // As light_level goes from LIGHT_AMBIENT_MINIMAL to LIGHT_AMBIENT_LIT,
1820 // dimming goes from 1.0 to 2.0.
1821 const float dimming_from_light = 1.0 + ( ( static_cast<float>( light_level ) -
1824
1825 // -1 because SOME math was changed from LIGHT_AMBIENT_MINIMAL to LIGHT_AMBIENT_LOW
1826 // but kept in other places.
1827 // *_LOW is the one actually used in math, *_MINIMAL is arbitrary.
1828 // TODO: Correct test cases and drop the ugliness
1829
1830 // This guarantees at least 1 tile of range
1831 static const float threshold_cap = vision::threshold_for_nv_range( 1 - 1 ) * LIGHT_AMBIENT_LOW /
1833
1834 return std::min( {static_cast<float>( LIGHT_AMBIENT_LOW ),
1835 vision::threshold_for_nv_range( nv_range - 1 ) * dimming_from_light,
1836 threshold_cap} );
1837}
@ DEBUG_NIGHTVISION
Definition: character.h:87
float nv_range
Definition: character.h:2110
static constexpr float LIGHT_AMBIENT_MINIMAL
Definition: lightmap.h:12
static constexpr float LIGHT_AMBIENT_LOW
Definition: lightmap.h:14
static constexpr float LIGHT_AMBIENT_LIT
Definition: lightmap.h:18
float threshold_for_nv_range(float range)
Returns the light level that darkness will have at this range from player.
Definition: character.cpp:1792

References DEBUG_NIGHTVISION, LIGHT_AMBIENT_LIT, LIGHT_AMBIENT_LOW, LIGHT_AMBIENT_MINIMAL, nv_range, vision::threshold_for_nv_range(), and vision_mode_cache.

Referenced by sight_range().

◆ get_weight()

units::mass Character::get_weight ( ) const
overridevirtual

Returns body weight plus weight of inventory and worn/wielded items.

Implements Creature.

Definition at line 3667 of file character.cpp.

3668{
3669 units::mass ret = 0_gram;
3670 units::mass wornWeight = std::accumulate( worn.begin(), worn.end(), 0_gram,
3671 []( units::mass sum, const item & itm ) {
3672 return sum + itm.weight();
3673 } );
3674
3675 ret += bodyweight(); // The base weight of the player's body
3676 ret += inv.weight(); // Weight of the stored inventory
3677 ret += wornWeight; // Weight of worn items
3678 ret += weapon.weight(); // Weight of wielded item
3679 ret += bionics_weight(); // Weight of installed bionics
3680 return ret;
3681}
units::mass bionics_weight() const
Definition: character.cpp:6883
units::mass bodyweight() const
Definition: character.cpp:6878
units::mass weight() const
Definition: inventory.cpp:994

References bionics_weight(), bodyweight(), inv, cata::hash64_detail::ret, weapon, inventory::weight(), item::weight(), and worn.

Referenced by vehicle::calc_mass_center(), can_mount(), npc::move_to(), swim_speed(), weigh_self_actor::use(), and game::walk_move().

◆ get_weight_string()

std::string Character::get_weight_string ( ) const

Definition at line 4552 of file character.cpp.

4553{
4554 double weight = convert_weight( bodyweight() );
4555 int display_weight = static_cast<int>( std::round( weight ) );
4556 return std::to_string( display_weight ) + " " + weight_units();
4557}
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References bodyweight(), convert_weight(), to_string(), and weight_units().

◆ get_working_arm_count()

int Character::get_working_arm_count ( ) const

Returns the number of functioning arms.

Definition at line 1287 of file character.cpp.

1288{
1290 return 0;
1291 }
1292
1293 int limb_count = 0;
1294 if( !is_limb_disabled( bodypart_id( "arm_l" ) ) ) {
1295 limb_count++;
1296 }
1297 if( !is_limb_disabled( bodypart_id( "arm_r" ) ) ) {
1298 limb_count++;
1299 }
1300 if( has_bionic( bio_blaster ) && limb_count > 0 ) {
1301 limb_count--;
1302 }
1303
1304 return limb_count;
1305}
static const bionic_id bio_blaster("bio_blaster")
bool is_limb_disabled(const bodypart_id &limb) const
Returns true if the limb is disabled(12.5% or less hp)
Definition: character.cpp:1320

References bio_blaster, has_active_mutation(), has_bionic(), is_limb_disabled(), and trait_SHELL2.

Referenced by player::can_wield(), has_two_arms(), melee_attack(), and avatar_action::plthrow().

◆ get_working_leg_count()

int Character::get_working_leg_count ( ) const

Returns the number of functioning legs.

Definition at line 1308 of file character.cpp.

1309{
1310 int limb_count = 0;
1311 if( !is_limb_broken( bodypart_id( "leg_l" ) ) ) {
1312 limb_count++;
1313 }
1314 if( !is_limb_broken( bodypart_id( "leg_r" ) ) ) {
1315 limb_count++;
1316 }
1317 return limb_count;
1318}

References is_limb_broken().

Referenced by character_martial_arts::can_leg_block(), can_run(), is_on_ground(), and avatar::set_movement_mode().

◆ getID()

character_id Character::getID ( ) const

Definition at line 477 of file character.cpp.

478{
479 return this->id;
480}

References id.

Referenced by add_addiction(), item::already_used_by_player(), talk_effect_t::apply(), apply_damage(), iuse::artifact(), mission::assign(), talk_function::assign_camp(), vehicle::assign_seat(), best_installer(), bionics_install_failure(), map::board_vehicle(), veh_interact::calc_overview(), debug_menu::character_edit_menu(), check_needs_extremes(), talk_function::clear_mission(), game::critter_by_id(), iuse::crowbar(), mattack::dermatik(), monster::die(), npc::die(), avatar::do_read(), npc::execute_action(), dig_activity_actor::finish(), hacking_activity_actor::finish(), npc::finish_read(), player::fire_gun(), talk_function::follow(), item::get_remaining_chapters(), player::hardcoded_effects(), heal(), talk_function::hostile(), hurtall(), npc::is_ally(), item_location::impl::item_on_person::item_on_person(), talk_function::leave(), avatar::load(), game::load(), npc::load_npc_template(), item::mark_as_used_by_player(), item::mark_chapter_as_read(), iuse::marloss(), marloss_common(), iuse::marloss_gel(), iuse::marloss_seed(), mend(), iuse::mininuke(), mount_creature(), mutagen_common_checks(), mutate_towards(), npc::mutiny(), iuse::mycus(), iuse::note_bionics(), kill_tracker::notify(), talk_function::npc_die(), mattack::nurse_operate(), mission::on_creature_death(), perform_install(), perform_uninstall(), npc::randomize(), avatar::read(), npc::regen_ai_cache(), rem_addiction(), Creature::remove_effect(), game::reset_npc_dispositions(), map::rotate(), talk_effect_fun_t::set_add_mission(), vehicle_part::set_crew(), npc::set_fac(), npc::set_known_to_u(), npc::setpos(), game::start_game(), npc::start_read(), talk_function::start_training(), talk_function::stop_guard(), player::store(), survive_random_encounter(), npc::talk_to_u(), teleport::teleport(), test_crossing_threshold(), player::throw_item(), activity_handlers::train_finish(), npc::travel_overmap(), game::validate_npc_followers(), vomit(), and wake_up().

◆ gibType()

field_type_id Character::gibType ( ) const
overridevirtual

Implements Creature.

Definition at line 498 of file character.cpp.

499{
500 return fd_gibs_flesh;
501}
field_type_id fd_gibs_flesh
Definition: field_type.cpp:338

References fd_gibs_flesh.

◆ global_omt_location()

tripoint_abs_omt Character::global_omt_location ( ) const

Returns the location of the player in global overmap terrain coordinates.

Definition at line 6351 of file character.cpp.

6352{
6353 // TODO: fix point types
6355}
virtual tripoint global_square_location() const
Global position, expressed in map square coordinate system (the most detailed coordinate system),...
Definition: character.cpp:6341
point ms_to_omt_copy(const point &p)
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493

References global_square_location(), and ms_to_omt_copy().

Referenced by talk_function::abandon_camp(), computer_session::action_map_sewer(), computer_session::action_map_subway(), computer_session::action_maps(), activate_bionic(), activate_mutation(), apply_persistent_morale(), iuse::artifact(), talk_function::assign_camp(), talk_function::basecamp_mission(), burn_fuel(), talk_function::caravan_dist(), ui::omap::choose_point(), talk_function::companion_choose_return(), talk_function::companion_list(), talk_function::companion_mission(), npc::consume_food_from_camp(), mission_start::create_hidden_lab_console(), mission_start::create_ice_lab_console(), mission_start::create_lab_console(), game::disp_NPCs(), item::display_name(), ui::omap::display_visible_weather(), ui::omap::display_weather(), game::do_turn(), overmap_ui::draw_ascii(), draw_env_compact(), draw_loc_labels(), draw_location_classic(), game::draw_minimap(), draw_minimap(), basecamp::faction_display(), npc::faction_display(), talk_function::field_build_1(), talk_function::field_build_2(), talk_function::field_harvest(), mission_start::find_safety(), overmapbuffer::fix_npcs(), get_basecamp(), get_mission_om_origin(), overmapbuffer::get_npcs_near_omt(), overmapbuffer::get_npcs_near_player(), overmap_ui::get_overmap_path_to(), npc::go_to_omt_destination(), talk_function::goto_location(), npc::guard_current_pos(), talk_function::individual_mission(), mission_start::kill_horde_master(), game::list_missions(), spell_effect::map_area(), trapfunc::map_regen(), npc::move(), overmap_los(), passive_power_gen(), game::perhaps_add_random_npc(), mission_start::place_deposit_box(), mission_start::place_npc_software(), player::process_turn(), npc::reach_omt_destination(), talk_function::recover_camp(), teleporter_callback::refresh(), npc::regen_ai_cache(), render_wind(), game::reset_npc_dispositions(), reveal_destination(), mission_start::reveal_lab_train_depot(), mission_util::reveal_om_ter(), conditional_t< T >::set_at_om_location(), npc::set_companion_mission(), npc::set_omt_destination(), talk_function::start_camp(), game::start_game(), activity_handlers::travel_do_turn(), npc::travel_overmap(), activity_handlers::tree_communion_do_turn(), update_bodytemp(), game::update_overmap_seen(), reveal_map_actor::use(), game::vertical_notes(), iuse::weather_tool(), npc::within_boundaries_of_camp(), and game::zones_manager().

◆ global_sm_location()

tripoint Character::global_sm_location ( ) const

◆ global_square_location()

tripoint Character::global_square_location ( ) const
virtual

Global position, expressed in map square coordinate system (the most detailed coordinate system), used by the map.

Reimplemented in npc.

Definition at line 6341 of file character.cpp.

6342{
6343 return get_map().getabs( position );
6344}
tripoint position
Definition: character.h:2058

References get_map(), map::getabs(), and position.

Referenced by global_omt_location(), and global_sm_location().

◆ handle_melee_wear()

bool Character::handle_melee_wear ( item shield,
float  wear_multiplier = 1.0f 
)

Calculates melee weapon wear-and-tear through use, returns true if item is destroyed.

Dexterity reduces chance of damaging your melee weapon Strength increases chance of damaging your melee weapon (NEGATIVE) Melee reduces chance of damaging your melee weapon

Definition at line 156 of file melee.cpp.

157{
158 if( wear_multiplier <= 0.0f ) {
159 return false;
160 }
161 // Here is where we handle wear and tear on things we use as melee weapons or shields.
162 if( shield.is_null() ) {
163 return false;
164 }
165
166 // UNBREAKABLE_MELEE items can't be damaged through melee combat usage.
167 if( shield.has_flag( "UNBREAKABLE_MELEE" ) ) {
168 return false;
169 }
170
171 /** @EFFECT_DEX reduces chance of damaging your melee weapon */
172
173 /** @EFFECT_STR increases chance of damaging your melee weapon (NEGATIVE) */
174
175 /** @EFFECT_MELEE reduces chance of damaging your melee weapon */
176 const float stat_factor = dex_cur / 2.0f
178 + ( 64.0f / std::max( str_cur, 4 ) );
179
180 float material_factor;
181
182 itype_id weak_comp;
183 itype_id big_comp = itype_id::NULL_ID();
184 // Fragile items that fall apart easily when used as a weapon due to poor construction quality
185 if( shield.has_flag( "FRAGILE_MELEE" ) ) {
186 const float fragile_factor = 6;
187 int weak_chip = INT_MAX;
188 units::volume big_vol = 0_ml;
189
190 // Items that should have no bearing on durability
191 const std::set<itype_id> blacklist = { itype_rag, itype_leather, itype_fur };
192
193 for( auto &comp : shield.components ) {
194 if( blacklist.count( comp.typeId() ) <= 0 ) {
195 if( weak_chip > comp.chip_resistance() ) {
196 weak_chip = comp.chip_resistance();
197 weak_comp = comp.typeId();
198 }
199 }
200 if( comp.volume() > big_vol ) {
201 big_vol = comp.volume();
202 big_comp = comp.typeId();
203 }
204 }
205 material_factor = ( weak_chip < INT_MAX ? weak_chip : shield.chip_resistance() ) / fragile_factor;
206 } else {
207 material_factor = shield.chip_resistance();
208 }
209 int damage_chance = static_cast<int>( stat_factor * material_factor / wear_multiplier );
210 // DURABLE_MELEE items are made to hit stuff and they do it well, so they're considered to be a lot tougher
211 // than other weapons made of the same materials.
212 if( shield.has_flag( "DURABLE_MELEE" ) ) {
213 damage_chance *= 4;
214 }
215
216 if( damage_chance > 0 && !one_in( damage_chance ) ) {
217 return false;
218 }
219
220 auto str = shield.tname(); // save name before we apply damage
221
222 if( !shield.inc_damage() ) {
223 add_msg_player_or_npc( m_bad, _( "Your %s is damaged by the force of the blow!" ),
224 _( "<npcname>'s %s is damaged by the force of the blow!" ),
225 str );
226 return false;
227 }
228
229 // Dump its contents on the ground
230 // Destroy irremovable mods, if any
231
232 for( auto mod : shield.gunmods() ) {
233 if( mod->is_irremovable() ) {
234 remove_item( *mod );
235 }
236 }
237
238 // Preserve item temporarily for component breakdown
239 item temp = shield;
240
241 shield.contents.spill_contents( pos() );
242
243 remove_item( shield );
244
245 // Breakdown fragile weapons into components
246 if( temp.has_flag( "FRAGILE_MELEE" ) && !temp.components.empty() ) {
247 add_msg_player_or_npc( m_bad, _( "Your %s breaks apart!" ),
248 _( "<npcname>'s %s breaks apart!" ),
249 str );
250
251 for( auto &comp : temp.components ) {
252 int break_chance = comp.typeId() == weak_comp ? 2 : 8;
253
254 if( one_in( break_chance ) ) {
255 add_msg_if_player( m_bad, _( "The %s is destroyed!" ), comp.tname() );
256 continue;
257 }
258
259 if( comp.typeId() == big_comp && !is_armed() ) {
260 wield( comp );
261 } else {
262 g->m.add_item_or_charges( pos(), comp );
263 }
264 }
265 } else {
266 add_msg_player_or_npc( m_bad, _( "Your %s is destroyed by the blow!" ),
267 _( "<npcname>'s %s is destroyed by the blow!" ),
268 str );
269 }
270
271 return true;
272}
virtual bool wield(item &target)=0
Removes currently wielded item (if any) and replaces it with the target item.
bool spill_contents(const tripoint &pos)
int chip_resistance(bool worst=false) const
Returns resistance to being damaged by attack against the item itself.
Definition: item.cpp:6036
bool inc_damage(damage_type dt)
Increment item damage by itype::damage_scale constrained by max_damage.
Definition: item.cpp:6097
static const itype_id itype_rag("rag")
static const itype_id itype_fur("fur")
static const itype_id itype_leather("leather")

References _, Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), item::chip_resistance(), item::components, item::contents, dex_cur, g, get_skill_level(), item::gunmods(), item::has_flag(), item::inc_damage(), is_armed(), item::is_null(), itype_fur, itype_leather, itype_rag, m_bad, string_id< itype >::NULL_ID(), one_in(), pos(), visitable< Character >::remove_item(), skill_melee, item_contents::spill_contents(), str_cur, item::tname(), and wield().

Referenced by block_hit(), melee_special_effects(), player::reach_attack(), and smash().

◆ has_active_bionic()

bool Character::has_active_bionic ( const bionic_id b) const

Returns true if the player has the entered bionic id and it is powered on.

Definition at line 1890 of file character.cpp.

1891{
1892 for( const bionic &i : *my_bionics ) {
1893 if( i.id == b ) {
1894 return ( i.powered && i.incapacitated_time == 0_turns );
1895 }
1896 }
1897 return false;
1898}

References b, and my_bionics.

Referenced by absorb_hit(), activate_bionic(), active_light(), adjust_for_focus(), attack_cost(), player::basic_symbol_color(), burn_move_stamina(), character_martial_arts::can_arm_block(), can_feed_furnace_with(), can_feed_reactor_with(), character_martial_arts::can_leg_block(), player::can_sleep(), crit_chance(), avatar::do_read(), do_skill_rust(), game::do_turn(), draw_bionics_titlebar(), draw_skills_tab(), player::eat(), iuse::ehandcuffs(), npc::finish_read(), fun_for(), get_env_resist(), get_hit_weapon(), ranged::gunmode_checks_weapon(), game::handle_action(), has_fire(), has_nv(), hearing_ability(), player::impact(), in_climate_control(), is_blind(), is_deaf(), is_immune_damage(), is_immune_field(), ma_requirements::is_valid_character(), game::item_action_menu(), trapfunc::ledge(), melee_attack(), melee_special_effects(), game::monmove(), mut_cbm_encumb(), player::on_hit(), game::on_move_effects(), perform_technique(), character_martial_arts::pick_style(), trapfunc::pit(), trapfunc::pit_glass(), trapfunc::pit_spikes(), map::player_in_field(), player::process_items(), recalc_sight_limits(), npc::recharge_cbm(), game::remoteveh(), reset_stats(), mattack::riotbot(), roll_bash_damage(), roll_cut_damage(), roll_stab_damage(), run_cost(), player::search_surroundings(), sees_with_specials(), game::setremoteveh(), player::sleep_spot(), iuse::solarpack(), suffer_from_radiation(), player::throw_item(), throw_range(), player::try_to_sleep(), player::uncanny_dodge(), update_health(), update_needs(), update_stamina(), use_charges(), use_fire(), and npc::wants_to_recharge_cbm().

◆ has_active_item()

bool Character::has_active_item ( const itype_id id) const

Whether the player carries an active item of the given item type.

Definition at line 2564 of file character.cpp.

2565{
2566 return has_item_with( [id]( const item & it ) {
2567 return it.active && it.typeId() == id;
2568 } );
2569}

References item::active, visitable< Character >::has_item_with(), and item::typeId().

Referenced by deactivate_bionic(), game::handle_action(), iuse::mp3(), game::remoteveh(), and game::setremoteveh().

◆ has_active_mutation()

◆ has_activity() [1/2]

bool Character::has_activity ( const activity_id type) const

◆ has_activity() [2/2]

bool Character::has_activity ( const std::vector< activity_id > &  types) const

Check if player currently has any of the given activities.

Definition at line 9241 of file character.cpp.

9242{
9243 return std::find( types.begin(), types.end(), activity.id() ) != types.end();
9244}
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)

References activity, detail::find(), and player_activity::id().

◆ has_addiction()

bool Character::has_addiction ( add_type  type) const

Returns true if the player has an addiction of the specified type.

Definition at line 1938 of file suffer.cpp.

1939{
1940 return std::any_of( addictions.begin(), addictions.end(),
1941 [type]( const addiction & ad ) {
1942 return ad.type == type && ad.intensity >= MIN_ADDICTION_LEVEL;
1943 } );
1944}

References addictions, and type.

Referenced by player::sleep_spot().

◆ has_alarm_clock()

bool Character::has_alarm_clock ( ) const

Returns true if the player or their vehicle has an alarm clock.

Definition at line 835 of file character.cpp.

836{
837 map &here = get_map();
838 return ( has_item_with_flag( "ALARMCLOCK", true ) ||
839 ( here.veh_at( pos() ) &&
840 !empty( here.veh_at( pos() )->vehicle().get_avail_parts( "ALARMCLOCK" ) ) ) ||
842}
static const bionic_id bio_watch("bio_watch")
bool has_item_with_flag(const std::string &flag, bool need_charges=false) const
Definition: character.cpp:9595

References bio_watch, get_map(), has_bionic(), has_item_with_flag(), pos(), map::veh_at(), and vehicle.

Referenced by player::hardcoded_effects(), sleep(), and wait().

◆ has_any_bionic()

bool Character::has_any_bionic ( ) const

Returns true if the player has any bionic.

Definition at line 1900 of file character.cpp.

1901{
1902 return !get_bionics().empty();
1903}

References get_bionics().

Referenced by mattack::nurse_operate().

◆ has_artifact_with()

bool Character::has_artifact_with ( art_effect_passive  effect) const
virtual

Reimplemented in npc.

Definition at line 3223 of file character.cpp.

3224{
3226 return true;
3227 }
3228 for( auto &i : worn ) {
3229 if( i.has_effect_when_worn( effect ) ) {
3230 return true;
3231 }
3232 }
3233 return has_item_with( [effect]( const item & it ) {
3234 return it.has_effect_when_carried( effect );
3235 } );
3236}
bool has_effect_when_carried(art_effect_passive effect) const
Does the item provide the artifact effect when it is carried?
Definition: item.cpp:9578
bool has_effect_when_wielded(art_effect_passive effect) const
Does the item provide the artifact effect when it is wielded?
Definition: item.cpp:9560

References item::has_effect_when_carried(), item::has_effect_when_wielded(), visitable< Character >::has_item_with(), weapon, and worn.

Referenced by active_light(), player::basic_symbol_color(), deal_damage(), player::hardcoded_effects(), is_immune_damage(), is_invisible(), melee_attack(), recalc_sight_limits(), player::recalc_speed_bonus(), suffer_from_artifacts(), suffer_while_awake(), update_health(), game::walk_move(), and weight_capacity().

◆ has_base_trait()

bool Character::has_base_trait ( const trait_id b) const

Returns true if the player has the entered starting trait.

Definition at line 121 of file mutation.cpp.

122{
123 // Look only at base traits
124 return my_traits.find( b ) != my_traits.end();
125}

References b, and my_traits.

Referenced by build_mut_dependency_map(), do_purify(), wish_mutate_callback::key(), mutate_towards(), old_mutate(), player::power_mutations_ui(), iuse::purify_iv(), iuse::purify_smart(), remove_mutation(), and debug_menu::wishmutate().

◆ has_bionic()

bool Character::has_bionic ( const bionic_id b) const

Returns true if the player has the entered bionic id.

Definition at line 1880 of file character.cpp.

1881{
1882 for( const bionic_id &bid : get_bionics() ) {
1883 if( bid == b ) {
1884 return true;
1885 }
1886 }
1887 return false;
1888}

References b, and get_bionics().

Referenced by add_bionic(), iexamine::autodoc(), autodoc_internal(), bionics_install_failure(), talk_trial::calc_chance(), calc_needs_rates(), character_martial_arts::can_arm_block(), character_martial_arts::can_leg_block(), npc::can_read(), can_uninstall_bionic(), install_bionic_actor::can_use(), item::color_in_inventory(), consume_effects(), player::consume_med(), activity_handlers::cracking_do_turn(), deactivate_bionic(), draw_env_compact(), draw_speed_tab(), draw_time_classic(), player::eat(), iuse::einktabletpc(), iexamine::fireplace(), avatar::get_book_reader(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), get_temp(), player::get_weapon_dispersion(), get_working_arm_count(), player::hardcoded_effects(), has_alarm_clock(), has_enough_anesth(), has_fire(), has_watch(), is_immune_effect(), player::load(), game::on_move_effects(), activity_handlers::operation_do_turn(), overmap_sight_range(), iexamine::pay_gas(), sounds::process_sound_markers(), read_speed(), recalc_sight_limits(), player::recalc_speed_bonus(), iuse::robotcontrol(), roll_cut_damage(), roll_stab_damage(), run_cost(), iexamine::safe(), conditional_t< T >::set_has_bionics(), sight_impaired(), suffer_from_asthma(), suffer_from_bad_bionics(), suffer_from_radiation(), suffer_from_sunburn(), suffer_while_underwater(), try_start_hacking(), update_bodytemp(), consume_drug_iuse::use(), game::use_computer(), use_fire(), volume_capacity_reduced_by(), avatar::wake_up(), game::walk_move(), and will_eat().

◆ has_charges()

bool Character::has_charges ( const itype_id it,
int  quantity,
const std::function< bool(const item &)> &  filter = return_true<item> 
) const

Definition at line 9612 of file character.cpp.

9614{
9615 if( it == itype_fire || it == itype_apparatus ) {
9616 return has_fire( quantity );
9617 }
9618 if( it == itype_UPS && is_mounted() &&
9619 mounted_creature.get()->has_flag( MF_RIDEABLE_MECH ) ) {
9620 auto mons = mounted_creature.get();
9621 return quantity <= mons->battery_item->ammo_remaining();
9622 }
9623 if( it == itype_bio_armor ) {
9624 int mod_qty = 0;
9625 float efficiency = 1;
9626 for( const bionic &bio : *my_bionics ) {
9627 if( bio.powered && bio.info().has_flag( flag_BIONIC_ARMOR_INTERFACE ) ) {
9628 efficiency = std::max( efficiency, bio.info().fuel_efficiency );
9629 }
9630 }
9631 if( efficiency == 1 ) {
9632 debugmsg( "Player lacks a bionic armor interface with fuel efficiency field." );
9633 }
9634 mod_qty = quantity / efficiency;
9635 return ( has_power() && get_power_level() >= units::from_kilojoule( mod_qty ) );
9636 }
9637 return charges_of( it, quantity, filter ) == quantity;
9638}
static const itype_id itype_fire("fire")
static const flag_str_id flag_BIONIC_ARMOR_INTERFACE("BIONIC_ARMOR_INTERFACE")
static const itype_id itype_apparatus("apparatus")
bool has_power() const
Definition: character.cpp:2012
bool has_fire(int quantity) const
Definition: character.cpp:9759

References visitable< Character >::charges_of(), debugmsg, flag_BIONIC_ARMOR_INTERFACE, units::from_kilojoule(), get_power_level(), has_fire(), has_power(), is_mounted(), itype_apparatus, itype_bio_armor, itype_fire, itype_UPS, MF_RIDEABLE_MECH, mounted_creature, and my_bionics.

Referenced by iexamine::arcfurnace_empty(), iuse::cable_attach(), can_eat(), iexamine::can_fertilize(), player::can_reload(), cauterize_actor::can_use(), craft_command::check_item_components_missing(), craft_command::check_tool_components_missing(), consume_charges(), player::consume_med(), consume_remote_fuel(), player::craft_consume_tools(), iuse::ecig(), activity_handlers::fertilize_plot_do_turn(), find_remote_fuel(), crafting::find_tool_component(), iuse::firecracker_pack(), player::gunmod_add(), ranged::gunmode_checks_weapon(), has_enough_charges(), has_fire(), npc::heal_self(), iexamine::kiln_empty(), npc::move(), iexamine::pay_gas(), game::reload(), talk_effect_fun_t::set_consume_item(), conditional_t< T >::set_has_items(), talk_effect_fun_t::set_u_sell_item(), smoker_activate(), iuse::smoking(), suffer_from_asthma(), try_consume(), try_start_hacking(), consume_drug_iuse::use(), use_charges_if_avail(), and use_fire().

◆ has_child_flag()

bool Character::has_child_flag ( const trait_id flag) const

Returns true if the player has the entered mutation child flag.

Definition at line 1485 of file mutation.cpp.

1486{
1487 for( const trait_id &elem : flag->replacements ) {
1488 const trait_id &tmp = elem;
1489 if( has_trait( tmp ) || has_child_flag( tmp ) ) {
1490 return true;
1491 }
1492 }
1493 return false;
1494}
bool has_child_flag(const trait_id &flag) const
Returns true if the player has the entered mutation child flag.
Definition: mutation.cpp:1485

References has_child_flag(), has_trait(), and mutation_branch::replacements.

Referenced by has_child_flag(), mutate_towards(), mutation_ok(), and remove_child_flag().

◆ has_destination()

◆ has_destination_activity()

bool Character::has_destination_activity ( ) const

◆ has_distant_destination()

bool Character::has_distant_destination ( ) const

Definition at line 10492 of file character.cpp.

10493{
10496}
static const activity_id ACT_TRAVELLING("ACT_TRAVELLING")
std::vector< tripoint_abs_omt > omt_path
Definition: character.h:972

References ACT_TRAVELLING, get_destination_activity(), has_destination(), player_activity::id(), player_activity::is_null(), and omt_path.

Referenced by game::cancel_activity_or_ignore_query(), game::cancel_activity_query(), and game::do_turn().

◆ has_enough_anesth()

bool Character::has_enough_anesth ( const itype cbm,
player patient 
)

Has enough anesthetic for surgery.

Definition at line 1826 of file bionics.cpp.

1827{
1828 if( !cbm->bionic ) {
1829 debugmsg( "has_enough_anesth( const itype *cbm ): %s is not a bionic", cbm->get_id() );
1830 return false;
1831 }
1832
1835 return true;
1836 }
1837
1838 const int weight = 7;
1839 const requirement_data req_anesth = *requirement_id( "anesthetic" ) *
1840 cbm->bionic->difficulty * 2 * weight;
1841
1843}
static const bionic_id bio_painkiller("bio_painkiller")
static const trait_id trait_DEBUG_BIONICS("DEBUG_BIONICS")
static const trait_id trait_NOPAIN("NOPAIN")
bool is_crafting_component(const item &component)
Default filter for crafting component searches.
Definition: item.h:2275
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:861
bool can_make_with_inventory(const inventory &crafting_inv, const std::function< bool(const item &)> &filter, int batch=1, cost_adjustment=cost_adjustment::none) const
Returns true if the requirements are fufilled by the filtered inventory.
string_id< requirement_data > requirement_id
Definition: type_id.h:136

References bio_painkiller, itype::bionic, requirement_data::can_make_with_inventory(), crafting_inventory(), debugmsg, itype::get_id(), has_bionic(), has_trait(), is_crafting_component(), trait_DEBUG_BIONICS, and trait_NOPAIN.

Referenced by bionic_install_preset::get_denial(), and bionic_uninstall_preset::get_denial().

◆ has_enough_charges()

bool Character::has_enough_charges ( const item it,
bool  show_msg 
) const

Has the item enough charges to invoke its use function? Also checks if UPS from this player is used instead of item charges.

Definition at line 7475 of file character.cpp.

7476{
7477 if( !it.is_tool() || !it.ammo_required() ) {
7478 return true;
7479 }
7480 if( it.is_power_armor() ) {
7481 if( ( as_player()->can_interface_armor() && has_charges( itype_bio_armor, it.ammo_required() ) ) ||
7483 it.ammo_sufficient() ) {
7484 return true;
7485 }
7486
7487 if( show_msg ) {
7488 if( it.has_flag( flag_USE_UPS ) ) {
7490 vgettext( "Your %s needs %d charge, from some UPS or a Bionic Power Interface.",
7491 "Your %s needs %d charges, from some UPS or a Bionic Power Interface.",
7492 it.ammo_required() ),
7493 it.tname(), it.ammo_required() );
7494 } else {
7496 vgettext( "Your %s needs %d charge, from a Bionic Power Interface.",
7497 "Your %s needs %d charges, from a Bionic Power Interface.",
7498 it.ammo_required() ),
7499 it.tname(), it.ammo_required() );
7500 }
7501 }
7502 return false;
7503 }
7504 if( it.has_flag( flag_USE_UPS ) ) {
7505 if( has_charges( itype_UPS, it.ammo_required() ) || it.ammo_sufficient() ) {
7506 return true;
7507 }
7508 if( show_msg ) {
7510 vgettext( "Your %s needs %d charge from some UPS.",
7511 "Your %s needs %d charges from some UPS.",
7512 it.ammo_required() ),
7513 it.tname(), it.ammo_required() );
7514 }
7515 return false;
7516 } else if( !it.ammo_sufficient() ) {
7517 if( show_msg ) {
7519 vgettext( "Your %s has %d charge but needs %d.",
7520 "Your %s has %d charges but needs %d.",
7521 it.ammo_remaining() ),
7522 it.tname(), it.ammo_remaining(), it.ammo_required() );
7523 }
7524 return false;
7525 }
7526 return true;
7527}
bool ammo_sufficient(int qty=1) const
Check if sufficient ammo is loaded for given number of uses.
Definition: item.cpp:7313

References Creature::add_msg_if_player(), item::ammo_remaining(), item::ammo_required(), item::ammo_sufficient(), Creature::as_player(), flag_USE_UPS(), has_charges(), item::has_flag(), item::is_power_armor(), item::is_tool(), itype_bio_armor, itype_UPS, m_info, item::tname(), and vgettext().

Referenced by activatable_inventory_preset::get_denial(), invoke_item(), iuse::jackhammer(), and iuse::note_bionics().

◆ has_fire()

bool Character::has_fire ( int  quantity) const

Definition at line 9759 of file character.cpp.

9760{
9761 // TODO: Replace this with a "tool produces fire" flag.
9762
9763 if( get_map().has_nearby_fire( pos() ) ) {
9764 return true;
9765 } else if( has_item_with_flag( "FIRE" ) ) {
9766 return true;
9767 } else if( has_item_with_flag( "FIRESTARTER" ) ) {
9768 auto firestarters = all_items_with_flag( "FIRESTARTER" );
9769 for( auto &i : firestarters ) {
9770 if( !i->type->can_have_charges() ) {
9771 const use_function *usef = i->type->get_use( "firestarter" );
9772 if( !usef ) {
9773 debugmsg( "failed to get use func 'firestarter' for item '%s'", i->typeId().c_str() );
9774 continue;
9775 }
9776 const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
9777 if( actor->can_use( *this->as_character(), *i, false, tripoint_zero ).success() ) {
9778 return true;
9779 }
9780 } else if( has_charges( i->typeId(), quantity ) ) {
9781 return true;
9782 }
9783 }
9784 } else if( has_active_bionic( bio_tools ) && get_power_level() > quantity * 5_kJ ) {
9785 return true;
9786 } else if( has_bionic( bio_lighter ) && get_power_level() > quantity * 5_kJ ) {
9787 return true;
9788 } else if( has_bionic( bio_laser ) && get_power_level() > quantity * 5_kJ ) {
9789 return true;
9790 } else if( is_npc() ) {
9791 // HACK: A hack to make NPCs use their Molotovs
9792 return true;
9793 }
9794 return false;
9795}
static const bionic_id bio_lighter("bio_lighter")
static const bionic_id bio_laser("bio_laser")
static const bionic_id bio_tools("bio_tools")
std::vector< const item * > all_items_with_flag(const std::string &flag) const
All items that have the given flag (item::has_flag).
Definition: character.cpp:9605
Starts a fire instantly.
Definition: iuse_actor.h:529
ret_val< bool > can_use(const Character &, const item &, bool, const tripoint &) const override
iuse_actor * get_actor_ptr()
Definition: iuse.h:315

References all_items_with_flag(), bio_laser, bio_lighter, bio_tools, firestarter_actor::can_use(), debugmsg, use_function::get_actor_ptr(), get_map(), get_power_level(), has_active_bionic(), has_bionic(), has_charges(), has_item_with_flag(), Creature::is_npc(), pos(), and tripoint_zero.

Referenced by has_charges(), and symbol_color().

◆ has_grab_break_tec()

bool Character::has_grab_break_tec ( ) const
overridevirtual

Returns true if the player has a grab breaking technique available.

Implements Creature.

Definition at line 1209 of file martialarts.cpp.

1210{
1211 return martial_arts_data->has_grab_break_tec();
1212}

References martial_arts_data.

Referenced by player::can_grab_break(), deal_damage(), and mattack::grab().

◆ has_item_with_flag()

bool Character::has_item_with_flag ( const std::string &  flag,
bool  need_charges = false 
) const

Definition at line 9595 of file character.cpp.

9596{
9597 return has_item_with( [&flag, &need_charges]( const item & it ) {
9598 if( it.is_tool() && need_charges ) {
9599 return it.has_flag( flag ) && it.type->tool->max_charges ? it.charges > 0 : it.has_flag( flag );
9600 }
9601 return it.has_flag( flag );
9602 } );
9603}

References item::has_flag(), visitable< Character >::has_item_with(), and item::is_tool().

Referenced by draw_env_compact(), draw_time_classic(), npc::faction_display(), get_temp(), has_alarm_clock(), has_fire(), has_watch(), loot(), overmap_sight_range(), npc::reach_omt_destination(), and use_fire().

◆ has_mabuff()

bool Character::has_mabuff ( const mabuff_id buff_id) const

Returns true if the player has any martial arts buffs attached.

Definition at line 1202 of file martialarts.cpp.

1203{
1204 return search_ma_buff_effect( *effects, [&id]( const ma_buff & b, const effect & ) {
1205 return b.id == id;
1206 } );
1207}
static bool search_ma_buff_effect(const C &container, F f)

References b, Creature::effects, id, and search_ma_buff_effect().

Referenced by ma_requirements::is_valid_character().

◆ has_max_power()

bool Character::has_max_power ( ) const

Definition at line 2017 of file character.cpp.

2018{
2019 return max_power_level > 0_kJ;
2020}

References max_power_level.

Referenced by bionics_install_failure(), power_stat(), conditional_t< T >::set_has_bionics(), and suffer_from_bad_bionics().

◆ has_morale()

bool Character::has_morale ( const morale_type type) const

Definition at line 9116 of file character.cpp.

9117{
9118 return morale->has( type );
9119}

References morale, and type.

Referenced by player::fire_gun(), suffer_from_other_mutations(), and iuse::towel_common().

◆ has_morale_to_craft()

bool Character::has_morale_to_craft ( ) const

Definition at line 330 of file crafting.cpp.

331{
332 return get_morale_level() >= -50;
333}
int get_morale_level() const
Definition: character.cpp:9100

References get_morale_level().

Referenced by game::butcher(), and iuse::multicooker().

◆ has_morale_to_read()

bool Character::has_morale_to_read ( ) const

Definition at line 9136 of file character.cpp.

9137{
9138 return get_morale_level() >= -40;
9139}

References get_morale_level().

Referenced by avatar::get_book_reader().

◆ has_nv()

bool Character::has_nv ( )

Returns true if the player has some form of night vision.

Definition at line 3632 of file character.cpp.

3633{
3634 static bool nv = false;
3635
3636 if( !nv_cached ) {
3637 nv_cached = true;
3638 nv = ( worn_with_flag( flag_GNV_EFFECT ) ||
3641 }
3642
3643 return nv;
3644}
static const std::string flag_GNV_EFFECT("GNV_EFFECT")
static const std::string flag_EFFECT_NIGHT_VISION("EFFECT_NIGHT_VISION")
static const bionic_id bio_night_vision("bio_night_vision")
bool has_effect_with_flag(const std::string &flag, body_part bp=num_bp) const
Check if creature has any effect with the given flag.
Definition: creature.cpp:1201

References bio_night_vision, flag_EFFECT_NIGHT_VISION(), flag_GNV_EFFECT(), has_active_bionic(), Creature::has_effect_with_flag(), nv_cached, and worn_with_flag().

Referenced by recalc_sight_limits().

◆ has_opposite_trait()

bool Character::has_opposite_trait ( const trait_id flag) const

Returns true if the player has a trait which cancels the entered trait.

Definition at line 9925 of file character.cpp.

9926{
9927 for( const trait_id &i : flag->cancels ) {
9928 if( has_trait( i ) ) {
9929 return true;
9930 }
9931 }
9932 for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
9933 for( const trait_id &canceled_trait : mut.first->cancels ) {
9934 if( canceled_trait == flag ) {
9935 return true;
9936 }
9937 }
9938 }
9939 return false;
9940}
std::vector< trait_id > cancels
Definition: mutation.h:260

References mutation_branch::cancels, has_trait(), and my_mutations.

Referenced by known_magic::can_learn_spell(), and player::has_conflicting_trait().

◆ has_power()

bool Character::has_power ( ) const

Definition at line 2012 of file character.cpp.

2013{
2014 return power_level > 0_kJ;
2015}

References power_level.

Referenced by player::can_sleep(), has_charges(), player::try_to_sleep(), iuse_transform::use(), set_transform_iuse::use(), and use_charges().

◆ has_stashed_activity()

bool Character::has_stashed_activity ( ) const

Definition at line 984 of file character.cpp.

985{
986 return static_cast<bool>( stashed_outbounds_activity );
987}

References stashed_outbounds_activity.

Referenced by npc::move().

◆ has_trait()

bool Character::has_trait ( const trait_id b) const
overridevirtual

Returns true if the player has the entered trait.

Reimplemented from Creature.

Definition at line 103 of file mutation.cpp.

104{
105 return my_mutations.count( b ) || enchantment_cache->get_mutations().count( b );
106}

References b, enchantment_cache, and my_mutations.

Referenced by absorb_hit(), activate_mutation(), add_addiction(), add_bionic(), player::add_pain_msg(), add_traits(), addict_effect(), adjust_for_focus(), alcohol(), allergy_type(), iuse::anticonvulsant(), iuse::antiparasitic(), apply_damage(), apply_persistent_morale(), monster::attitude(), iexamine::autodoc(), autodoc_internal(), iexamine::bars(), base_comfort_value(), player::basic_symbol_color(), bionics_pl_skill(), iuse::blech(), iuse::blood_draw(), bloodType(), activity_handlers::build_do_turn(), burn_move_stamina(), calc_all_parts_hp(), talk_trial::calc_chance(), player::calc_focus_equilibrium(), calc_needs_rates(), player::can_continue_craft(), can_eat(), can_install_bionics(), spell::can_learn(), player::can_lift(), can_pick_weight(), npc::can_read(), cauterize_actor::can_use(), install_bionic_actor::can_use(), can_wear(), cauterize_actor::cauterize_effect(), iexamine::chainfence(), check_needs_extremes(), game::check_safe_mode_allowed(), game::cleanup_at_end(), item::color_in_inventory(), talk_function::commune_farmfield(), talk_function::companion_mission(), veh_interact::complete_vehicle(), consume_effects(), player::consume_item(), player::consume_items(), player::consume_tools(), iuse::contacts(), game::control_vehicle(), player::craft_consume_tools(), crafting_inventory(), player::crafting_success_roll(), avatar::create(), craft_command::create_in_progress_craft(), iuse::datura(), deal_damage(), debug_vision(), mattack::dermatik(), trap::detect_trap(), monster::die(), character_display::disp_info(), avatar::disp_morale(), do_purify(), game::do_turn(), construct::done_vehicle(), overmap_ui::draw_ascii(), draw_limb_health(), overmap_ui::draw_om_sidebar(), draw_speed_tab(), drench(), player::eat(), eff_fun_spores(), iuse::einktabletpc(), game::extended_description(), player::fall_damage_mod(), talk_function::field_harvest(), game::find_or_make_stairs(), player::fine_detail_vision_mod(), npc::finish_read(), player::fire_gun(), floor_warmth(), iexamine::flower_dahlia(), talk_function::forage_return(), npc::form_opinion(), fun_for(), fungal_effects::fungalize(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_dodge(), get_env_resist(), get_face_type(), get_hunger_description(), get_miss_reason(), npc::get_monster_faction(), overmap_ui::get_overmap_neighbors(), get_pain_description(), character_effects::get_pain_penalty(), get_shout_volume(), player::gunmod_add(), player::gunmod_installation_odds(), game::handle_action(), player::hardcoded_effects(), hardcoded_mutation_attack(), iexamine::harvest_plant(), has_child_flag(), has_enough_anesth(), player::has_higher_trait(), player::has_lower_trait(), has_opposite_trait(), player::has_same_type_trait(), hearing_ability(), hit_roll(), hurtall(), player::immune_to(), in_climate_control(), install_bionics(), introduce_into_anesthesia(), irradiate(), is_deaf(), character_funcs::is_fun_to_read(), is_immune_damage(), is_immune_effect(), is_immune_field(), is_invisible(), wish_mutate_callback::key(), game::knockback(), talk_function::labor_return(), known_magic::learn_spell(), trapfunc::ledge(), iexamine::ledge(), player::load(), marloss_common(), marloss_prevented(), iuse::meditate(), melee_attack(), mend(), player::mend_item(), iuse::meth(), player::mod_pain(), modify_morale(), modify_stimulation(), game::mon_info_update(), avatar_action::move(), iuse::multicooker(), mutate(), mutate_category(), mutate_towards(), mutation_chances(), mutation_ok(), iuse::mycus(), old_mutate(), player::on_hit(), on_hurt(), npc::on_load(), iexamine::pay_gas(), perform_install(), pick_part_to_heal(), activity_handlers::pickaxe_finish(), trapfunc::pit(), trapfunc::pit_glass(), trapfunc::pit_spikes(), game::place_player(), iuse::plantblech(), player_can_build(), player_can_see_to_build(), map::player_in_field(), iuse::poison(), iuse::portable_game(), player::practice(), print_health(), game::print_terrain_info(), player::process_effects_internal(), item::process_litcig(), player::process_one_effect(), sounds::process_sound_markers(), player::process_turn(), iuse::purify_iv(), iuse::purify_smart(), avatar::randomize(), npc::randomize(), react_to_felt_pain(), avatar::read(), recalc_sight_limits(), player::recalc_speed_bonus(), wish_mutate_callback::refresh(), remove_child_flag(), remove_mutation(), player::reset_stats(), firestarter_actor::resolve_firestarter_use(), iuse::robotcontrol(), talk_trial::roll(), roll_bash_damage(), rooted(), rooted_message(), iexamine::rubble(), run_cost(), npc::say(), talk_function::scavenging_patrol_return(), sees_with_specials(), player::select_item_component(), conditional_t< T >::set_has_any_trait(), conditional_t< T >::set_has_trait(), set_traits(), shout(), iexamine::shrub_marloss(), sight_impaired(), iexamine::sign(), trapfunc::sinkhole(), player::sleep_spot(), game::slip_down(), avatar::steal(), stumble(), suffer(), suffer_from_addictions(), suffer_from_chemimbalance(), suffer_from_other_mutations(), suffer_from_radiation(), suffer_from_sunburn(), suffer_in_sunlight(), suffer_while_awake(), suffer_while_underwater(), swim_speed(), npc::talk_to_u(), test_crossing_threshold(), npc::time_to_read(), avatar::time_to_read(), player::toolmod_add(), activity_handlers::tree_communion_do_turn(), iexamine::tree_marloss(), try_reject_mutagen(), try_start_hacking(), player::try_to_sleep(), uninstall_bionic(), update_body(), player::update_body_wetness(), update_bodytemp(), update_needs(), game::update_stair_monsters(), update_stomach(), consume_drug_iuse::use(), cauterize_actor::use(), enzlave_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), game::use_computer(), game::vertical_move(), iuse::vibe(), volume_capacity_reduced_by(), player::vomit_mod(), game::walk_move(), iuse::weed_cake(), weed_msg(), weight_capacity(), weather_effect::wet_player(), will_eat(), and debug_menu::wishmutate().

◆ has_trait_flag()

bool Character::has_trait_flag ( const std::string &  b) const

Returns true if player has a trait with a flag.

Definition at line 108 of file mutation.cpp.

109{
110 // UGLY, SLOW, should be cached as my_mutation_flags or something
111 for( const trait_id &mut : get_mutations() ) {
112 const mutation_branch &mut_data = mut.obj();
113 if( mut_data.flags.count( b ) > 0 ) {
114 return true;
115 }
116 }
117
118 return false;
119}
std::set< std::string > flags
Definition: mutation.h:264

References b, mutation_branch::flags, and get_mutations().

Referenced by consider_butchery(), do_skill_rust(), mod_rad(), mod_thirst(), player::practice(), conditional_t< T >::set_has_trait_flag(), spell::spell_fail(), enzlave_actor::use(), and will_eat().

◆ has_two_arms()

bool Character::has_two_arms ( ) const

Returns true if the player has two functioning arms.

Returns true if the character has two functioning arms.

Definition at line 1280 of file character.cpp.

1281{
1282 return get_working_arm_count() >= 2;
1283}
int get_working_arm_count() const
Returns the number of functioning arms.
Definition: character.cpp:1287

References get_working_arm_count().

Referenced by can_wear(), player::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), map::player_in_field(), and mattack::riotbot().

◆ has_watch()

bool Character::has_watch ( ) const

Returns true if the player or their vehicle has a watch.

Definition at line 844 of file character.cpp.

845{
846 map &here = get_map();
847 return ( has_item_with_flag( "WATCH", true ) ||
848 ( here.veh_at( pos() ) &&
849 !empty( here.veh_at( pos() )->vehicle().get_avail_parts( "WATCH" ) ) ) ||
851}

References bio_watch, get_map(), has_bionic(), has_item_with_flag(), pos(), map::veh_at(), and vehicle.

Referenced by draw_loc_labels(), draw_time(), draw_time_classic(), game::list_missions(), and wait().

◆ has_weapon()

bool Character::has_weapon ( ) const
overridevirtual

Implements Creature.

Definition at line 10362 of file character.cpp.

10363{
10364 return !unarmed_attack();
10365}
bool unarmed_attack() const
True if unarmed or wielding a weapon with the UNARMED_WEAPON flag.
Definition: melee.cpp:150

References unarmed_attack().

Referenced by perform_technique(), and pick_technique().

◆ head_cloth_encumbrance()

int Character::head_cloth_encumbrance ( ) const

Returns the total encumbrance of all SKINTIGHT and HELMET_COMPAT items coveringi the head.

Definition at line 8924 of file character.cpp.

8925{
8926 int ret = 0;
8927 for( auto &i : worn ) {
8928 const item *worn_item = &i;
8929 if( i.covers( bp_head ) && !i.has_flag( flag_SEMITANGIBLE ) &&
8930 ( worn_item->has_flag( flag_HELMET_COMPAT ) || worn_item->has_flag( flag_SKINTIGHT ) ) ) {
8931 ret += worn_item->get_encumber( *this );
8932 }
8933 }
8934 return ret;
8935}

References bp_head, flag_HELMET_COMPAT(), flag_SEMITANGIBLE(), flag_SKINTIGHT(), item::get_encumber(), item::has_flag(), cata::hash64_detail::ret, and worn.

Referenced by can_wear().

◆ heal()

void Character::heal ( const bodypart_id healed,
int  dam 
)

Heals a body_part for dam.

Definition at line 8654 of file character.cpp.

8655{
8656 if( !is_limb_broken( healed ) ) {
8657 int effective_heal = std::min( dam, get_part_hp_max( healed ) - get_part_hp_cur( healed ) );
8658 mod_part_hp_cur( healed, effective_heal );
8659 g->events().send<event_type::character_heals_damage>( getID(), effective_heal );
8660 }
8661}
@ character_heals_damage

References character_heals_damage, g, Creature::get_part_hp_cur(), Creature::get_part_hp_max(), getID(), is_limb_broken(), and Creature::mod_part_hp_cur().

Referenced by enforce_minimum_healing(), heal_actor::finish_using(), give_aid_to(), healall(), process_bionic(), regen(), and suffer_water_damage().

◆ healall()

void Character::healall ( int  dam)

Heals all body parts for dam.

Definition at line 8663 of file character.cpp.

8664{
8665 for( const bodypart_id &bp : get_all_body_parts() ) {
8666 heal( bp, dam );
8667 mod_part_healed_total( bp, dam );
8668 }
8669}
void mod_part_healed_total(const bodypart_id &id, int mod)
Definition: creature.cpp:1600

References Creature::get_all_body_parts(), heal(), and Creature::mod_part_healed_total().

Referenced by iuse::artifact(), consume_effects(), player::hardcoded_effects(), spell::heal(), iuse::jet_injector(), melee_attack(), iuse::mycus(), regen(), and suffer_from_radiation().

◆ healed_bp()

void Character::healed_bp ( int  bp,
int  amount 
)

Definition at line 7888 of file character.cpp.

7889{
7890 healed_total[bp] += amount;
7891}

References healed_total.

Referenced by regen().

◆ healing_rate()

float Character::healing_rate ( float  at_rest_quality) const

Average hit points healed per turn.

Definition at line 6778 of file character.cpp.

6779{
6780 // TODO: Cache
6781 float heal_rate;
6782 if( !is_npc() ) {
6783 heal_rate = get_option< float >( "PLAYER_HEALING_RATE" );
6784 } else {
6785 heal_rate = get_option< float >( "NPC_HEALING_RATE" );
6786 }
6787 float awake_rate = heal_rate * mutation_value( "healing_awake" );
6788 float final_rate = 0.0f;
6789 if( awake_rate > 0.0f ) {
6790 final_rate += awake_rate;
6791 } else if( at_rest_quality < 1.0f ) {
6792 // Resting protects from rot
6793 final_rate += ( 1.0f - at_rest_quality ) * awake_rate;
6794 }
6795 float asleep_rate = 0.0f;
6796 if( at_rest_quality > 0.0f ) {
6797 asleep_rate = at_rest_quality * heal_rate * ( 1.0f + mutation_value( "healing_resting" ) );
6798 }
6799 if( asleep_rate > 0.0f ) {
6800 final_rate += asleep_rate * ( 1.0f + get_healthy() / 200.0f );
6801 }
6802
6803 // Most common case: awake player with no regenerative abilities
6804 // ~7e-5 is 1 hp per day, anything less than that is totally negligible
6805 static constexpr float eps = 0.000007f;
6806 add_msg( m_debug, "%s healing: %.6f", name, final_rate );
6807 if( std::abs( final_rate ) < eps ) {
6808 return 0.0f;
6809 }
6810
6811 float primary_hp_mod = mutation_value( "hp_modifier" );
6812 if( primary_hp_mod < 0.0f ) {
6813 // HP mod can't get below -1.0
6814 final_rate *= 1.0f + primary_hp_mod;
6815 }
6816
6817 return final_rate;
6818}

References add_msg(), get_healthy(), Creature::is_npc(), m_debug, mutation_value(), and name.

Referenced by regen().

◆ healing_rate_medicine()

float Character::healing_rate_medicine ( float  at_rest_quality,
const bodypart_id bp 
) const

Average hit points healed per turn from healing effects.

Definition at line 6820 of file character.cpp.

6821{
6822 float rate_medicine = 0.0f;
6823 float bandaged_rate = 0.0f;
6824 float disinfected_rate = 0.0f;
6825
6826 const effect &e_bandaged = get_effect( effect_bandaged, bp->token );
6827 const effect &e_disinfected = get_effect( effect_disinfected, bp->token );
6828
6829 if( !e_bandaged.is_null() ) {
6830 bandaged_rate += static_cast<float>( e_bandaged.get_amount( "HEAL_RATE" ) ) / to_turns<int>
6831 ( 24_hours );
6832 if( bp == bodypart_id( "head" ) ) {
6833 bandaged_rate *= e_bandaged.get_amount( "HEAL_HEAD" ) / 100.0f;
6834 }
6835 if( bp == bodypart_id( "torso" ) ) {
6836 bandaged_rate *= e_bandaged.get_amount( "HEAL_TORSO" ) / 100.0f;
6837 }
6838 }
6839
6840 if( !e_disinfected.is_null() ) {
6841 disinfected_rate += static_cast<float>( e_disinfected.get_amount( "HEAL_RATE" ) ) / to_turns<int>
6842 ( 24_hours );
6843 if( bp == bodypart_id( "head" ) ) {
6844 disinfected_rate *= e_disinfected.get_amount( "HEAL_HEAD" ) / 100.0f;
6845 }
6846 if( bp == bodypart_id( "torso" ) ) {
6847 disinfected_rate *= e_disinfected.get_amount( "HEAL_TORSO" ) / 100.0f;
6848 }
6849 }
6850
6851 rate_medicine += bandaged_rate + disinfected_rate;
6852 rate_medicine *= 1.0f + mutation_value( "healing_resting" );
6853 rate_medicine *= 1.0f + at_rest_quality;
6854
6855 // increase healing if character has both effects
6856 if( !e_bandaged.is_null() && !e_disinfected.is_null() ) {
6857 rate_medicine *= 2;
6858 }
6859
6860 if( get_healthy() > 0.0f ) {
6861 rate_medicine *= 1.0f + get_healthy() / 200.0f;
6862 } else {
6863 rate_medicine *= 1.0f + get_healthy() / 400.0f;
6864 }
6865 float primary_hp_mod = mutation_value( "hp_modifier" );
6866 if( primary_hp_mod < 0.0f ) {
6867 // HP mod can't get below -1.0
6868 rate_medicine *= 1.0f + primary_hp_mod;
6869 }
6870 return rate_medicine;
6871}
int get_amount(std::string arg, bool reduced=false) const
Returns the amount of a modifier type applied when a new effect is first added.
Definition: effect.cpp:974

References effect_bandaged, effect_disinfected, effect::get_amount(), Creature::get_effect(), get_healthy(), effect::is_null(), and mutation_value().

Referenced by regen().

◆ hearing_ability()

float Character::hearing_ability ( ) const

Definition at line 10287 of file character.cpp.

10288{
10289 float volume_multiplier = 1.0;
10290
10291 // Mutation/Bionic volume modifiers
10293 volume_multiplier *= 3.5;
10294 }
10295 if( has_trait( trait_PER_SLIME ) ) {
10296 // Random hearing :-/
10297 // (when it's working at all, see player.cpp)
10298 // changed from 0.5 to fix Mac compiling error
10299 volume_multiplier *= ( rng( 1, 2 ) );
10300 }
10301
10302 volume_multiplier *= Character::mutation_value( "hearing_modifier" );
10303
10304 if( has_effect( effect_deaf ) ) {
10305 // Scale linearly up to 30 minutes
10306 volume_multiplier *= ( 30_minutes - get_effect_dur( effect_deaf ) ) / 30_minutes;
10307 }
10308
10309 if( has_effect( effect_earphones ) ) {
10310 volume_multiplier *= .25;
10311 }
10312
10313 return volume_multiplier;
10314}
static const trait_id trait_PER_SLIME("PER_SLIME")
static const efftype_id effect_deaf("deaf")
static const bionic_id bio_ears("bio_ears")
static const bionic_id bio_earplugs("bio_earplugs")
static const efftype_id effect_earphones("earphones")

References bio_earplugs, bio_ears, effect_deaf, effect_earphones, Creature::get_effect_dur(), has_active_bionic(), Creature::has_effect(), has_trait(), mutation_value(), rng(), and trait_PER_SLIME.

Referenced by can_hear(), and sounds::process_sound_markers().

◆ heat_emission()

void Character::heat_emission ( int  b,
int  fuel_energy 
)

Handle heat from exothermic power generation.

Definition at line 1455 of file bionics.cpp.

1456{
1457 const bionic &bio = ( *my_bionics )[b];
1458 if( !bio.info().exothermic_power_gen ) {
1459 return;
1460 }
1461 const float efficiency = bio.info().fuel_efficiency;
1462
1463 const int heat_prod = fuel_energy * ( 1.0f - efficiency );
1464 const int heat_level = std::min( heat_prod / 10, 4 );
1465 const emit_id hotness = emit_id( "emit_hot_air" + std::to_string( heat_level ) + "_cbm" );
1466 map &here = get_map();
1467 if( hotness.is_valid() ) {
1468 const int heat_spread = std::max( heat_prod / 10 - heat_level, 1 );
1469 here.emit_field( pos(), hotness, heat_spread );
1470 }
1471 for( const std::pair<const bodypart_str_id, int> &bp : bio.info().occupied_bodyparts ) {
1472 add_effect( effect_heating_bionic, 2_seconds, bp.first->token, heat_prod );
1473 }
1474}
static const efftype_id effect_heating_bionic("heating_bionic")
bool exothermic_power_gen
If true this bionic emits heat when producing power.
Definition: bionics.h:73
string_id< emit > emit_id
Definition: type_id.h:44

References Creature::add_effect(), b, effect_heating_bionic, map::emit_field(), bionic_data::exothermic_power_gen, bionic_data::fuel_efficiency, get_map(), bionic::info(), string_id< T >::is_valid(), bionic_data::occupied_bodyparts, pos(), and to_string().

Referenced by burn_fuel(), and passive_power_gen().

◆ height()

int Character::height ( ) const

Definition at line 6959 of file character.cpp.

6960{
6961 switch( get_size() ) {
6962 case MS_TINY:
6963 return init_height - 100;
6964 case MS_SMALL:
6965 return init_height - 50;
6966 case MS_MEDIUM:
6967 return init_height;
6968 case MS_LARGE:
6969 return init_height + 50;
6970 case MS_HUGE:
6971 return init_height + 100;
6972 default:
6973 break;
6974 }
6975
6976 debugmsg( "Invalid size class" );
6977 abort();
6978}
@ MS_TINY
Definition: creature.h:58
@ MS_LARGE
Definition: creature.h:61
@ MS_SMALL
Definition: creature.h:59
@ MS_HUGE
Definition: creature.h:62
@ MS_MEDIUM
Definition: creature.h:60

References abort, debugmsg, get_size(), init_height, MS_HUGE, MS_LARGE, MS_MEDIUM, MS_SMALL, and MS_TINY.

Referenced by bodyweight(), height_string(), and set_base_height().

◆ height_string()

std::string Character::height_string ( ) const

Definition at line 6944 of file character.cpp.

6945{
6946 const bool metric = get_option<std::string>( "DISTANCE_UNITS" ) == "metric";
6947
6948 if( metric ) {
6949 std::string metric_string = _( "%d cm" );
6950 return string_format( metric_string, height() );
6951 }
6952
6953 int total_inches = std::round( height() / 2.54 );
6954 int feet = std::floor( total_inches / 12 );
6955 int remainder_inches = total_inches % 12;
6956 return string_format( "%d\'%d\"", feet, remainder_inches );
6957}

References _, height(), and string_format().

Referenced by draw_stats_info(), and draw_stats_tab().

◆ hit_roll()

float Character::hit_roll ( ) const
overridevirtual

Returns the player's basic hit roll that is compared to the target's dodge roll.

Implements Creature.

Definition at line 297 of file melee.cpp.

298{
299 // Dexterity, skills, weapon and martial arts
300 float hit = get_melee_hit_base();
301
302 // Farsightedness makes us hit worse
303 if( has_trait( trait_HYPEROPIC ) && !worn_with_flag( "FIX_FARSIGHT" ) &&
305 hit -= 2.0f;
306 }
307
308 //Unstable ground chance of failure
310 hit *= 0.75f;
311 }
312
313 hit *= std::max( 0.25f, 1.0f - encumb( bp_torso ) / 100.0f );
314
315 return melee::melee_hit_range( hit );
316}
float get_melee_hit_base() const
Returns weapon skill.
Definition: melee.cpp:291
float melee_hit_range(float accuracy)
Once the accuracy (sum of modifiers) of an attack has been determined, this is used to actually roll ...
Definition: melee.cpp:2416

References bp_torso, effect_bouldering, effect_contacts, encumb(), get_melee_hit_base(), Creature::has_effect(), has_trait(), melee::melee_hit_range(), trait_HYPEROPIC, and worn_with_flag().

Referenced by player::disarm(), melee_attack(), perform_special_attacks(), and scored_crit().

◆ hitall()

int Character::hitall ( int  dam,
int  vary,
Creature source 
)

Harms all body parts for dam, with armor reduction.

If vary > 0 damage to parts are random within vary % (1-100)

Definition at line 8689 of file character.cpp.

8690{
8691 int damage_taken = 0;
8692 for( int i = 0; i < num_hp_parts; i++ ) {
8693 const bodypart_id bp = convert_bp( hp_to_bp( static_cast<hp_part>( i ) ) ).id();
8694 int ddam = vary ? dam * rng( 100 - vary, 100 ) / 100 : dam;
8695 int cut = 0;
8696 auto damage = damage_instance::physical( ddam, cut, 0 );
8697 damage_taken += deal_damage( source, bp, damage ).total_damage();
8698 }
8699 return damage_taken;
8700}
static body_part hp_to_bp(hp_part hpart)
Converts an hp_part to a body_part.
Definition: character.cpp:6604
int_id< T > id() const
Translate the string based it to the matching integer based id.
Definition: ammo_effect.cpp:54

References convert_bp(), deal_damage(), hp_to_bp(), string_id< T >::id(), num_hp_parts, damage_instance::physical(), rng(), and dealt_damage_instance::total_damage().

Referenced by game::forced_door_closing(), and vehicle::part_collision().

◆ hp_to_bp()

body_part Character::hp_to_bp ( hp_part  hpart)
static

Converts an hp_part to a body_part.

Definition at line 6604 of file character.cpp.

6605{
6606 switch( hpart ) {
6607 case hp_head:
6608 return bp_head;
6609 case hp_torso:
6610 return bp_torso;
6611 case hp_arm_l:
6612 return bp_arm_l;
6613 case hp_arm_r:
6614 return bp_arm_r;
6615 case hp_leg_l:
6616 return bp_leg_l;
6617 case hp_leg_r:
6618 return bp_leg_r;
6619 default:
6620 return num_bp;
6621 }
6622}

References bp_arm_l, bp_arm_r, bp_head, bp_leg_l, bp_leg_r, bp_torso, hp_arm_l, hp_arm_r, hp_head, hp_leg_l, hp_leg_r, hp_torso, and num_bp.

Referenced by iexamine::autodoc(), cauterize_actor::cauterize_effect(), draw_limb_health(), heal_actor::finish_using(), hitall(), player::impact(), pick_part_to_heal(), map::player_in_field(), regen(), heal_actor::use_healing_item(), and npc::wear_if_wanted().

◆ hurtall()

void Character::hurtall ( int  dam,
Creature source,
bool  disturb = true 
)

Hurts all body parts for dam, no armor reduction.

Definition at line 8671 of file character.cpp.

8672{
8673 if( is_dead_state() || has_trait( trait_DEBUG_NODMG ) || dam <= 0 ) {
8674 return;
8675 }
8676
8677 for( const bodypart_id &bp : get_all_body_parts( true ) ) {
8678 // Don't use apply_damage here or it will annoy the player with 6 queries
8679 const int dam_to_bodypart = std::min( dam, get_part_hp_cur( bp ) );
8680 mod_part_hp_cur( bp, - dam_to_bodypart );
8681 g->events().send<event_type::character_takes_damage>( getID(), dam_to_bodypart );
8682 }
8683
8684 // Low pain: damage is spread all over the body, so not as painful as 6 hits in one part
8685 mod_pain( dam );
8686 on_hurt( source, disturb );
8687}

References character_takes_damage, g, Creature::get_all_body_parts(), Creature::get_part_hp_cur(), getID(), has_trait(), Creature::is_dead_state(), Creature::mod_pain(), Creature::mod_part_hp_cur(), on_hurt(), and trait_DEBUG_NODMG.

Referenced by trapfunc::drain(), player::hardcoded_effects(), marloss_common(), trapfunc::pit(), map::player_in_field(), game::process_artifact(), regen(), map::shake_vehicle(), suffer_from_bad_bionics(), suffer_from_radiation(), trapfunc::tripwire(), and try_reject_mutagen().

◆ i_add()

item & Character::i_add ( item  it,
bool  should_stack = true 
)

Definition at line 2324 of file character.cpp.

2325{
2326 itype_id item_type_id = it.typeId();
2327 last_item = item_type_id;
2328
2329 if( it.is_food() || it.is_ammo() || it.is_gun() || it.is_armor() ||
2330 it.is_book() || it.is_tool() || it.is_melee() || it.is_food_container() ) {
2331 inv.unsort();
2332 }
2333
2334 // if there's a desired invlet for this item type, try to use it
2335 bool keep_invlet = false;
2336 const invlets_bitset cur_inv = allocated_invlets();
2337 for( auto iter : inv.assigned_invlet ) {
2338 if( iter.second == item_type_id && !cur_inv[iter.first] ) {
2339 it.invlet = iter.first;
2340 keep_invlet = true;
2341 break;
2342 }
2343 }
2344 auto &item_in_inv = inv.add_item( it, keep_invlet, true, should_stack );
2345 item_in_inv.on_pickup( *this );
2346 cached_info.erase( "reloadables" );
2347 return item_in_inv;
2348}
itype_id last_item
Definition: character.h:1528
std::map< std::string, double > cached_info
Definition: character.h:2079
std::bitset< std::numeric_limits< char >::max()> allocated_invlets() const
Only use for UI things.
Definition: character.cpp:2550
std::map< char, itype_id > assigned_invlet
Definition: inventory.h:99
bool is_food_container() const
Definition: item.cpp:6452
bool is_book() const
Definition: item.cpp:6553
void on_pickup(Character &p)
Callback when a player starts carrying the item.
Definition: item.cpp:4401
bool is_melee(damage_type dt) const
Is this item an effective melee weapon for the given damage type?
Definition: item.cpp:6521

References inventory::add_item(), allocated_invlets(), inventory::assigned_invlet, cached_info, inv, item::invlet, item::is_ammo(), item::is_armor(), item::is_book(), item::is_food(), item::is_food_container(), item::is_gun(), item::is_melee(), item::is_tool(), last_item, item::on_pickup(), item::typeId(), and inventory::unsort().

Referenced by player::add_or_drop_with_msg(), iuse::adrenaline_injector(), iuse::arrow_flammable(), debug_menu::debug(), fetch_activity(), give_item_to(), handle_harvest(), i_add_or_drop(), mount_creature(), npc::mug_player(), iuse::multicooker(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), pick_one_up(), npc::pick_up_item(), iuse::purify_smart(), iuse::radiocar(), item::reload(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_item_inventory(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), gun_actor::shoot(), avatar::steal(), npc::stow_item(), npc_trading::transfer_items(), ammobelt_actor::use(), iuse::vaccine(), and game::wield().

◆ i_add_or_drop()

bool Character::i_add_or_drop ( item it,
int  qty = 1 
)

Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.

An optional qty can be provided (and will perform better than separate calls).

Definition at line 2462 of file character.cpp.

2463{
2464 bool retval = true;
2465 bool drop = it.made_of( LIQUID );
2466 bool add = it.is_gun() || !it.is_irremovable();
2467 inv.assign_empty_invlet( it, *this );
2468 map &here = get_map();
2469 for( int i = 0; i < qty; ++i ) {
2470 drop |= !can_pick_weight( it, !get_option<bool>( "DANGEROUS_PICKUPS" ) ) || !can_pick_volume( it );
2471 if( drop ) {
2472 retval &= !here.add_item_or_charges( pos(), it ).is_null();
2473 } else if( add ) {
2474 i_add( it );
2475 }
2476 }
2477
2478 return retval;
2479}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2324
bool can_pick_volume(const item &it) const
Definition: character.cpp:2890
void assign_empty_invlet(item &it, const Character &p, bool force=false)
Definition: inventory.cpp:1148
bool is_irremovable() const
Definition: item.cpp:6619
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4184

References om_direction::add(), map::add_item_or_charges(), inventory::assign_empty_invlet(), can_pick_volume(), can_pick_weight(), drop(), get_map(), i_add(), inv, item::is_gun(), item::is_irremovable(), item::is_null(), LIQUID, item::made_of(), and pos().

Referenced by activate_mutation(), salvage_actor::cut_up(), drop_or_handle(), heal_actor::finish_using(), player::gunmod_remove(), item_contents::handle_liquid_or_spill(), iexamine::pedestal_wyrm(), item::reload(), remove_radio_mod(), player::unload(), consume_drug_iuse::use(), bandolier_actor::use(), iexamine::vending(), and debug_menu::wishitem().

◆ i_add_to_container()

int Character::i_add_to_container ( const item it,
bool  unloading 
)

Try to find a container/s on character containing ammo of type it.typeId() and add charges until the container is full.

Parameters
unloadingDo not try to add to a container when the item was intentionally unloaded.
Returns
Remaining charges which could not be stored in a container.

Definition at line 2288 of file character.cpp.

2289{
2290 int charges = it.charges;
2291 if( !it.is_ammo() || unloading ) {
2292 return charges;
2293 }
2294
2295 const itype_id item_type = it.typeId();
2296 auto add_to_container = [&it, &charges]( item & container ) {
2297 auto &contained_ammo = container.contents.front();
2298 if( contained_ammo.charges < container.ammo_capacity() ) {
2299 const int diff = container.ammo_capacity() - contained_ammo.charges;
2300 //~ %1$s: item name, %2$s: container name
2301 add_msg( pgettext( "container", "You put the %1$s in your %2$s." ), it.tname(), container.tname() );
2302 if( diff > charges ) {
2303 contained_ammo.charges += charges;
2304 return 0;
2305 } else {
2306 contained_ammo.charges = container.ammo_capacity();
2307 return charges - diff;
2308 }
2309 }
2310 return charges;
2311 };
2312
2313 visit_items( [ & ]( item * item ) {
2314 if( charges > 0 && item->is_ammo_container() && item_type == item->contents.front().typeId() ) {
2315 charges = add_to_container( *item );
2316 item->handle_pickup_ownership( *this );
2317 }
2318 return VisitResponse::NEXT;
2319 } );
2320
2321 return charges;
2322}
bool is_ammo_container() const
Definition: item.cpp:6506

References add_msg(), item::charges, item::contents, item_contents::front(), item::is_ammo(), item::is_ammo_container(), NEXT, pgettext(), item::tname(), item::typeId(), and visitable< Character >::visit_items().

Referenced by player::add_or_drop_with_msg(), and pick_one_up().

◆ i_at() [1/2]

◆ i_at() [2/2]

const item & Character::i_at ( int  position) const

Definition at line 2388 of file character.cpp.

2389{
2390 if( position == -1 ) {
2391 return weapon;
2392 }
2393 if( position < -1 ) {
2394 int worn_index = worn_position_to_index( position );
2395 if( static_cast<size_t>( worn_index ) < worn.size() ) {
2396 auto iter = worn.begin();
2397 std::advance( iter, worn_index );
2398 return *iter;
2399 }
2400 }
2401
2402 return inv.find_item( position );
2403}
const item & find_item(int position) const
Definition: inventory.cpp:797

References inventory::find_item(), inv, position, weapon, worn, and worn_position_to_index().

◆ i_rem() [1/2]

item Character::i_rem ( const item it)

Remove a specific item from player possession.

The item is compared by pointer. Contents of the item are removed as well.

Parameters
itA pointer to the item to be removed. The item must exists in the players possession (one can use has_item to check for this).
Returns
A copy of the removed item.

Definition at line 2445 of file character.cpp.

2446{
2447 auto tmp = remove_items_with( [&it]( const item & i ) {
2448 return &i == it;
2449 }, 1 );
2450 if( tmp.empty() ) {
2451 debugmsg( "did not found item %s to remove it!", it->tname() );
2452 return item();
2453 }
2454 return tmp.front();
2455}
std::list< item > remove_items_with(const std::function< bool(const item &)> &filter, int count=INT_MAX)
Removes items contained by this instance which match the filter.

References debugmsg, visitable< Character >::remove_items_with(), and item::tname().

◆ i_rem() [2/2]

item Character::i_rem ( int  pos)

Remove a specific item from player possession.

The item is compared by pointer. Contents of the item are removed as well.

Parameters
posThe item position of the item to be removed. The item must exists, use has_item to check this.
Returns
A copy of the removed item.

Definition at line 2427 of file character.cpp.

2428{
2429 item tmp;
2430 if( pos == -1 ) {
2431 tmp = weapon;
2432 weapon = item();
2433 return tmp;
2434 } else if( pos < -1 && pos > worn_position_to_index( worn.size() ) ) {
2435 auto iter = worn.begin();
2436 std::advance( iter, worn_position_to_index( pos ) );
2437 tmp = *iter;
2438 tmp.on_takeoff( *this );
2439 worn.erase( iter );
2440 return tmp;
2441 }
2442 return inv.remove_item( pos );
2443}
item remove_item(const item *it)
Remove a specific item from the inventory.
Definition: inventory.cpp:715

References inv, item::on_takeoff(), pos(), inventory::remove_item(), weapon, worn, and worn_position_to_index().

Referenced by apply_damage(), mattack::bio_op_disarm(), iuse::blood_draw(), player::consume(), consume_charges(), player::disarm(), drop_invalid_inventory(), npc::drop_items(), iuse::fish_trap(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), i_rem_keep_contents(), invoke_item(), activity_handlers::lockpicking_finish(), iuse::lumber(), npc::mug_player(), npc_throw(), pickup::obtain_and_tokenize_items(), iuse::radiocar(), player::reduce_charges(), avatar::steal(), player::store(), tidy_activity(), unpack_actor::use(), and avatar::wield().

◆ i_rem_keep_contents()

void Character::i_rem_keep_contents ( int  idx)

Definition at line 2457 of file character.cpp.

2458{
2459 i_rem( idx ).spill_contents( pos() );
2460}

References i_rem(), pos(), and item::spill_contents().

Referenced by damage_item(), and sew_advanced_actor::use().

◆ in_climate_control()

bool Character::in_climate_control ( )

Returns true if the player is in a climate controlled area or armor.

Definition at line 3844 of file character.cpp.

3845{
3846 bool regulated_area = false;
3847 // Check
3849 return true;
3850 }
3851 map &here = get_map();
3853 in_sleep_state() ) {
3854 return true;
3855 }
3856 for( auto &w : worn ) {
3857 if( w.has_flag( flag_CLIMATE_CONTROL.str() ) ) {
3858 return true;
3859 }
3860 }
3862 // save CPU and simulate acclimation.
3864 if( const optional_vpart_position vp = here.veh_at( pos() ) ) {
3865 // TODO: (?) Force player to scrounge together an AC unit
3866 regulated_area = (
3867 vp->is_inside() && // Already checks for opened doors
3868 vp->vehicle().total_power_w( true ) > 0 // Out of gas? No AC for you!
3869 );
3870 }
3871 // TODO: AC check for when building power is implemented
3872 last_climate_control_ret = regulated_area;
3873 if( !regulated_area ) {
3874 // Takes longer to cool down / warm up with AC, than it does to step outside and feel cruddy.
3875 next_climate_control_check += 40_turns;
3876 }
3877 } else {
3879 }
3880 return regulated_area;
3881}
static const flag_str_id flag_CLIMATE_CONTROL("CLIMATE_CONTROL")
static const bionic_id bio_climate("bio_climate")

References bio_climate, flag_CLIMATE_CONTROL, flag_FUNGUS(), get_map(), has_active_bionic(), map::has_flag_ter_or_furn(), has_trait(), in_sleep_state(), last_climate_control_ret, next_climate_control_check, pos(), string_id< T >::str(), trait_M_SKIN3, calendar::turn, map::veh_at(), and worn.

Referenced by update_bodytemp().

◆ in_sleep_state()

◆ in_species()

bool Character::in_species ( const species_id spec) const
overridevirtual

Reimplemented from Creature.

Definition at line 503 of file character.cpp.

504{
505 return spec == HUMAN;
506}
static const species_id HUMAN("HUMAN")

References HUMAN.

◆ initialize_stomach_contents()

void Character::initialize_stomach_contents ( )

Definition at line 195 of file stomach.cpp.

196{
198}

References stomach.

◆ install_bionics()

bool Character::install_bionics ( const itype type,
player installer,
bool  autodoc = false,
int  skill_level = -1 
)

Initialize all the values needed to start the operation player_activity.

Definition at line 2251 of file bionics.cpp.

2253{
2254 if( !type.bionic ) {
2255 debugmsg( "Tried to install NULL bionic" );
2256 return false;
2257 }
2258
2259 const bionic_id &bioid = type.bionic->id;
2260 const bionic_id &upbioid = bioid->upgraded_bionic;
2261 const int difficulty = type.bionic->difficulty;
2262 float adjusted_skill;
2263 int pl_skill;
2264 if( autodoc ) {
2265 adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
2268 skill_level );
2269 pl_skill = installer.bionics_pl_skill( skill_firstaid,
2272 skill_level );
2273 } else {
2274 adjusted_skill = installer.bionics_adjusted_skill( skill_electronics,
2277 skill_level );
2278 pl_skill = installer.bionics_pl_skill( skill_electronics,
2281 skill_level );
2282 }
2283 int chance_of_success = bionic_manip_cos( adjusted_skill, difficulty );
2284
2285 // Practice skills only if conducting manual installation
2286 if( !autodoc ) {
2287 installer.practice( skill_electronics, static_cast<int>( ( 100 - chance_of_success ) * 1.5 ) );
2288 installer.practice( skill_firstaid, static_cast<int>( ( 100 - chance_of_success ) * 1.0 ) );
2289 installer.practice( skill_mechanics, static_cast<int>( ( 100 - chance_of_success ) * 0.5 ) );
2290 }
2291
2292 int success = chance_of_success - rng( 0, 99 );
2293 if( installer.has_trait( trait_DEBUG_BIONICS ) ) {
2294 perform_install( bioid, upbioid, difficulty, success, pl_skill, "NOT_MED",
2295 bioid->canceled_mutations );
2296 return true;
2297 }
2298 assign_activity( ACT_OPERATION, to_moves<int>( difficulty * 20_minutes ) );
2299 activity.values.push_back( difficulty );
2300 activity.values.push_back( success );
2301 activity.values.push_back( units::to_joule( bioid->capacity ) );
2302 activity.values.push_back( pl_skill );
2303 activity.str_values.push_back( "install" );
2304 activity.str_values.push_back( bioid.str() );
2305
2306 if( installer.has_trait( trait_PROF_MED ) || installer.has_trait( trait_PROF_AUTODOC ) ) {
2307 activity.str_values.push_back( installer.disp_name( true ) );
2308 } else {
2309 activity.str_values.push_back( "NOT_MED" );
2310 }
2311 if( autodoc ) {
2312 activity.str_values.push_back( "true" );
2313 } else {
2314 activity.str_values.push_back( "false" );
2315 }
2316 for( const std::pair<const bodypart_str_id, int> &elem : bioid->occupied_bodyparts ) {
2317 add_effect( effect_under_op, difficulty * 20_minutes, elem.first->token, difficulty );
2318 }
2319
2320 return true;
2321}
static const activity_id ACT_OPERATION("ACT_OPERATION")
void perform_install(bionic_id bid, bionic_id upbid, int difficulty, int success, int pl_skill, const std::string &installer_name, const std::vector< trait_id > &trait_to_rem)
Success or failure of installation happens here.
Definition: bionics.cpp:2323
std::vector< std::string > str_values
void practice(const skill_id &id, int amount, int cap=99, bool suppress_warning=false)
This handles giving xp for a skill.
Definition: player.cpp:3858
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
bionic_id upgraded_bionic
Id of another bionic which this bionic can upgrade.
Definition: bionics.h:125

References ACT_OPERATION, activity, Creature::add_effect(), assign_activity(), iexamine::autodoc(), bionic_manip_cos(), bionics_adjusted_skill(), bionics_pl_skill(), bionic_data::canceled_mutations, bionic_data::capacity, debugmsg, disp_name(), effect_under_op, has_trait(), bionic_data::occupied_bodyparts, perform_install(), player::practice(), rng(), skill_computer, skill_electronics, skill_firstaid, skill_mechanics, string_id< T >::str(), player_activity::str_values, behavior::success, units::to_joule(), trait_DEBUG_BIONICS, trait_PROF_AUTODOC, trait_PROF_MED, type, bionic_data::upgraded_bionic, and player_activity::values.

Referenced by iexamine::autodoc(), and install_bionic_actor::use().

◆ introduce_into_anesthesia()

void Character::introduce_into_anesthesia ( const time_duration duration,
player installer,
bool  needs_anesthesia 
)

Handles process of introducing patient into anesthesia during Autodoc operations.

Requires anesthesia kits or NOPAIN mutation

Definition at line 2842 of file bionics.cpp.

2844{
2845 if( installer.has_trait( trait_DEBUG_BIONICS ) ) {
2846 installer.add_msg_if_player( m_info,
2847 _( "You tell the pain to bug off and proceed with the operation." ) );
2848 return;
2849 }
2850 installer.add_msg_player_or_npc( m_info,
2851 _( "You set up the operation step-by-step, configuring the Autodoc to manipulate a CBM." ),
2852 _( "<npcname> sets up the operation, configuring the Autodoc to manipulate a CBM." ) );
2853
2855 _( "You settle into position, sliding your right wrist into the couch's strap." ),
2856 _( "<npcname> settles into position, sliding their wrist into the couch's strap." ) );
2857 if( needs_anesthesia ) {
2858 //post-threshold medical mutants do not fear operations.
2861 _( "You feel excited as the operation starts." ) );
2862 }
2863
2865 _( "You feel a tiny pricking sensation in your right arm, and lose all sensation before abruptly blacking out." ) );
2866
2867 //post-threshold medical mutants with Deadened don't need anesthesia due to their inability to feel pain
2868 } else {
2869 //post-threshold medical mutants do not fear operations.
2872 _( "You feel excited as the Autodoc slices painlessly into you. You enjoy the sight of scalpels slicing you apart." ) );
2873 } else {
2875 _( "You stay very, very still, focusing intently on an interesting stain on the ceiling, as the Autodoc slices painlessly into you." ) );
2876 }
2877 }
2878
2879 //Pain junkies feel sorry about missed pain from operation.
2883 _( "As your consciousness slips away, you feel regret that you won't be able to enjoy the operation." ) );
2884 }
2885
2886 if( has_effect( effect_narcosis ) ) {
2887 const time_duration remaining_time = get_effect_dur( effect_narcosis );
2888 if( remaining_time <= duration ) {
2889 const time_duration top_off_time = duration - remaining_time;
2890 add_effect( effect_narcosis, top_off_time );
2891 fall_asleep( top_off_time );
2892 }
2893 } else {
2894 add_effect( effect_narcosis, duration );
2895 fall_asleep( duration );
2896 }
2897}
static const efftype_id effect_narcosis("narcosis")
static const trait_id trait_THRESH_MEDICAL("THRESH_MEDICAL")
static const trait_id trait_MASOCHIST_MED("MASOCHIST_MED")
static const trait_id trait_CENOBITE("CENOBITE")
static const trait_id trait_MASOCHIST("MASOCHIST")
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:4210
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:4205

References _, Creature::add_effect(), Creature::add_msg_if_player(), player::add_msg_if_player(), Creature::add_msg_player_or_npc(), player::add_msg_player_or_npc(), effect_narcosis, fall_asleep(), Creature::get_effect_dur(), Creature::has_effect(), has_trait(), m_info, m_mixed, trait_CENOBITE, trait_DEBUG_BIONICS, trait_MASOCHIST, trait_MASOCHIST_MED, and trait_THRESH_MEDICAL.

Referenced by iexamine::autodoc().

◆ inv_dump()

std::vector< item * > Character::inv_dump ( )

Definition at line 8973 of file character.cpp.

8974{
8975 std::vector<item *> ret;
8976 if( is_armed() && can_unwield( weapon ).success() ) {
8977 ret.push_back( &weapon );
8978 }
8979 for( auto &i : worn ) {
8980 ret.push_back( &i );
8981 }
8982 inv.dump( ret );
8983 return ret;
8984}
void dump(std::vector< item * > &dest)
Definition: inventory.cpp:788

References can_unwield(), inventory::dump(), inv, is_armed(), cata::hash64_detail::ret, behavior::success, weapon, and worn.

Referenced by npc::apply_ownership_to_inv(), are_requirements_nearby(), npc::die(), generic_multi_activity_locations(), irradiate(), game::load(), item_action_generator::map_actions_to_items(), place_corpse(), conditional_t< T >::set_has_stolen_item(), sleep(), game::start_game(), and tidy_activity().

◆ invalidate_crafting_inventory()

◆ invlet_to_item()

item * Character::invlet_to_item ( int  invlet)

Return the item pointer of the item with given invlet, return nullptr if the player does not have such an item with that invlet.

Don't use this on npcs. Only use the invlet in the user interface, otherwise always use the item position.

Definition at line 2364 of file character.cpp.

2365{
2366 // Invlets may come from curses, which may also return any kind of key codes, those being
2367 // of type int and they can become valid, but different characters when casted to char.
2368 // Example: KEY_NPAGE (returned when the player presses the page-down key) is 0x152,
2369 // casted to char would yield 0x52, which happens to be 'R', a valid invlet.
2370 if( linvlet > std::numeric_limits<char>::max() || linvlet < std::numeric_limits<char>::min() ) {
2371 return nullptr;
2372 }
2373 const char invlet = static_cast<char>( linvlet );
2374 item *invlet_item = nullptr;
2375 visit_items( [&invlet, &invlet_item]( item * it ) {
2376 if( it->invlet == invlet ) {
2377 invlet_item = it;
2378 return VisitResponse::ABORT;
2379 }
2380 // Visit top-level items only as UIs don't support nested items.
2381 // Also, inventory restack logic depends on this.
2382 return VisitResponse::SKIP;
2383 } );
2384 return invlet_item;
2385}

References item::invlet, SKIP, and visitable< Character >::visit_items().

Referenced by pick_one_up(), player::reassign_item(), inventory::restack(), player::sort_armor(), and game_menus::inv::swap_letters().

◆ invoke_item() [1/4]

bool Character::invoke_item ( item used)
virtual

As above two, but with position equal to current position.

Reimplemented in avatar, npc, avatar, and npc.

Definition at line 7336 of file character.cpp.

7337{
7338 return invoke_item( used, pos() );
7339}

References invoke_item(), and pos().

◆ invoke_item() [2/4]

bool Character::invoke_item ( item used,
const std::string &  method 
)
virtual

Reimplemented in avatar, npc, avatar, and npc.

Definition at line 7346 of file character.cpp.

7347{
7348 return invoke_item( used, method, pos() );
7349}

References invoke_item(), and pos().

◆ invoke_item() [3/4]

bool Character::invoke_item ( item used,
const std::string &  method,
const tripoint pt 
)
virtual

As above, but with a pre-selected method.

Debugmsg if this item doesn't have this method.

Reimplemented in avatar, npc, and avatar.

Definition at line 7351 of file character.cpp.

7352{
7353 if( !has_enough_charges( *used, true ) ) {
7354 return false;
7355 }
7356
7357 item *actually_used = used->get_usable_item( method );
7358 if( actually_used == nullptr ) {
7359 debugmsg( "Tried to invoke a method %s on item %s, which doesn't have this method",
7360 method.c_str(), used->tname() );
7361 return false;
7362 }
7363
7364 int charges_used = actually_used->type->invoke( *this->as_player(), *actually_used, pt, method );
7365 if( charges_used == 0 ) {
7366 return false;
7367 }
7368 // Prevent accessing the item as it may have been deleted by the invoked iuse function.
7369
7370 if( used->is_tool() || used->is_medication() || used->get_contained().is_medication() ) {
7371 return consume_charges( *actually_used, charges_used );
7372 } else if( used->is_bionic() || used->is_deployable() || method == "place_trap" ) {
7373 i_rem( used );
7374 return true;
7375 }
7376
7377 return false;
7378}
bool has_enough_charges(const item &it, bool show_msg) const
Has the item enough charges to invoke its use function? Also checks if UPS from this player is used i...
Definition: character.cpp:7475
bool consume_charges(item &used, int qty)
Consume charges of a tool or comestible item, potentially destroying it in the process.
Definition: character.cpp:7529
bool is_deployable() const
Definition: item.cpp:6792
item * get_usable_item(const std::string &use_name)
Checks this item and its contents (recursively) for types that have use_function with type use_name.
Definition: item.cpp:7806
bool is_bionic() const
Definition: item.cpp:6396
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:105

References Creature::as_player(), consume_charges(), debugmsg, item::get_contained(), item::get_usable_item(), has_enough_charges(), i_rem(), itype::invoke(), item::is_bionic(), item::is_deployable(), item::is_medication(), item::is_tool(), item::tname(), and item::type.

◆ invoke_item() [4/4]

bool Character::invoke_item ( item ,
const tripoint pt 
)
virtual

Asks how to use the item (if it has more than one use_method) and uses it.

Returns true if it destroys the item. Consumes charges from the item. Multi-use items are ONLY supported when all use_methods are iuse_actor!

Reimplemented in avatar, npc, avatar, and npc.

Definition at line 7341 of file character.cpp.

7342{
7343 return false;
7344}

Referenced by activate_bionic(), activate_mutation(), invoke_item(), avatar::invoke_item(), npc::invoke_item(), player::use(), and iexamine::use_furn_fake_item().

◆ irradiate()

bool Character::irradiate ( float  rads,
bool  bypass = false 
)

Handles mitigation and application of radiation.

Definition at line 1532 of file suffer.cpp.

1533{
1534 int rad_mut = 0;
1535 if( has_trait( trait_RADIOACTIVE3 ) ) {
1536 rad_mut = 3;
1537 } else if( has_trait( trait_RADIOACTIVE2 ) ) {
1538 rad_mut = 2;
1539 } else if( has_trait( trait_RADIOACTIVE1 ) ) {
1540 rad_mut = 1;
1541 }
1542
1543 if( rads > 0 ) {
1544 bool has_helmet = false;
1545 const bool power_armored = is_wearing_power_armor( &has_helmet );
1546 const bool rad_resist = power_armored || worn_with_flag( "RAD_RESIST" );
1547
1548 if( is_rad_immune() && !bypass ) {
1549 // Power armor and some high-tech gear protects completely from radiation
1550 rads = 0.0f;
1551 } else if( rad_resist && !bypass ) {
1552 rads /= 4.0f;
1553 }
1554
1555 if( has_effect( effect_iodine ) ) {
1556 // Radioactive mutation makes iodine less efficient (but more useful)
1557 rads *= 0.3f + 0.1f * rad_mut;
1558 }
1559
1560 int rads_max = roll_remainder( rads );
1561 mod_rad( rng( 0, rads_max ) );
1562
1563 // Apply rads to any radiation badges.
1564 for( item *const it : inv_dump() ) {
1565 if( it->typeId() != itype_rad_badge ) {
1566 continue;
1567 }
1568
1569 // Actual irradiation levels of badges and the player aren't precisely matched.
1570 // This is intentional.
1571 const int before = it->irradiation;
1572
1573 const int delta = rng( 0, rads_max );
1574 if( delta == 0 ) {
1575 continue;
1576 }
1577
1578 it->irradiation += delta;
1579
1580 // If in inventory (not worn), don't print anything.
1581 if( inv.has_item( *it ) ) {
1582 continue;
1583 }
1584
1585 // If the color hasn't changed, don't print anything.
1586 const std::string &col_before = rad_badge_color( before );
1587 const std::string &col_after = rad_badge_color( it->irradiation );
1588 if( col_before == col_after ) {
1589 continue;
1590 }
1591
1592 add_msg_if_player( m_warning, _( "Your radiation badge changes from %1$s to %2$s!" ),
1593 col_before, col_after );
1594 }
1595
1596 if( rads > 0.0f ) {
1597 return true;
1598 }
1599 }
1600 return false;
1601}
std::vector< item * > inv_dump()
Definition: character.cpp:8973
bool is_rad_immune() const
Returns true if the player is protected from radiation.
Definition: character.cpp:6276
std::string rad_badge_color(const int rad)
Definition: item.cpp:288
static const trait_id trait_RADIOACTIVE2("RADIOACTIVE2")
static const trait_id trait_RADIOACTIVE3("RADIOACTIVE3")
static const trait_id trait_RADIOACTIVE1("RADIOACTIVE1")
static const itype_id itype_rad_badge("rad_badge")
static const efftype_id effect_iodine("iodine")

References _, Creature::add_msg_if_player(), effect_iodine, Creature::has_effect(), visitable< T >::has_item(), has_trait(), inv, inv_dump(), is_rad_immune(), is_wearing_power_armor(), itype_rad_badge, m_warning, mod_rad(), rad_badge_color(), rng(), roll_remainder(), trait_RADIOACTIVE1, trait_RADIOACTIVE2, trait_RADIOACTIVE3, and worn_with_flag().

Referenced by trapfunc::glow(), modify_radiation(), map::player_in_field(), game::process_artifact(), mattack::science(), and suffer_from_radiation().

◆ is_armed()

◆ is_auto_moving()

bool Character::is_auto_moving ( ) const

Definition at line 10498 of file character.cpp.

10499{
10500 return destination_point.has_value();
10501}

References destination_point.

Referenced by game::handle_action(), and avatar_action::move().

◆ is_blind()

bool Character::is_blind ( ) const

◆ is_category_allowed() [1/2]

bool Character::is_category_allowed ( const std::string &  category) const

Definition at line 396 of file mutation.cpp.

397{
398 bool allowed = false;
399 bool restricted = false;
400 for( const trait_id &mut : get_mutations() ) {
401 for( const std::string &Ch_cat : mut.obj().allowed_category ) {
402 restricted = true;
403 if( Ch_cat == category ) {
404 allowed = true;
405 }
406 }
407 }
408 if( !restricted ) {
409 allowed = true;
410 }
411 return allowed;
412}

References get_mutations().

◆ is_category_allowed() [2/2]

bool Character::is_category_allowed ( const std::vector< std::string > &  category) const

Returns true if this category of mutation is allowed.

Definition at line 373 of file mutation.cpp.

374{
375 bool allowed = false;
376 bool restricted = false;
377 for( const trait_id &mut : get_mutations() ) {
378 if( !mut.obj().allowed_category.empty() ) {
379 restricted = true;
380 }
381 for( const std::string &Mu_cat : category ) {
382 if( mut.obj().allowed_category.count( Mu_cat ) ) {
383 allowed = true;
384 break;
385 }
386 }
387
388 }
389 if( !restricted ) {
390 allowed = true;
391 }
392 return allowed;
393
394}

References get_mutations().

Referenced by mutation_ok(), and old_mutate().

◆ is_deaf()

◆ is_elec_immune()

bool Character::is_elec_immune ( ) const
overridevirtual

Returns true is the player is protected from electric shocks.

Implements Creature.

Definition at line 6206 of file character.cpp.

6207{
6208 return is_immune_damage( DT_ELECTRIC );
6209}
bool is_immune_damage(damage_type) const override
Returns true if the player is immune to this kind of damage.
Definition: character.cpp:6233

References DT_ELECTRIC, and is_immune_damage().

Referenced by iuse::ehandcuffs(), is_immune_field(), and map::player_in_field().

◆ is_hauling()

bool Character::is_hauling ( ) const

Definition at line 9198 of file character.cpp.

9199{
9200 return hauling;
9201}
bool hauling
Definition: character.h:1520

References hauling.

Referenced by cancel_activity(), haul(), game::place_player(), avatar::set_movement_mode(), game::vertical_move(), and game::walk_move().

◆ is_hibernating()

bool Character::is_hibernating ( ) const

Returns if the player has hibernation mutation and is asleep and well fed.

Definition at line 5158 of file character.cpp.

References effect_sleep, get_kcal_percent(), get_thirst(), has_active_mutation(), Creature::has_effect(), trait_HIBERNATE, and very_thirsty.

Referenced by calc_needs_rates(), and update_needs().

◆ is_immune_damage()

bool Character::is_immune_damage ( damage_type  dt) const
overridevirtual

Returns true if the player is immune to this kind of damage.

Implements Creature.

Definition at line 6233 of file character.cpp.

6234{
6235 switch( dt ) {
6236 case DT_NULL:
6237 return true;
6238 case DT_TRUE:
6239 return false;
6240 case DT_BIOLOGICAL:
6241 return has_effect_with_flag( "EFFECT_BIO_IMMUNE" ) ||
6242 worn_with_flag( "BIO_IMMUNE" );
6243 case DT_BASH:
6244 return has_effect_with_flag( "EFFECT_BASH_IMMUNE" ) ||
6245 worn_with_flag( "BASH_IMMUNE" );
6246 case DT_CUT:
6247 return has_effect_with_flag( "EFFECT_CUT_IMMUNE" ) ||
6248 worn_with_flag( "CUT_IMMUNE" );
6249 case DT_ACID:
6250 return has_trait( trait_ACIDPROOF ) ||
6251 has_effect_with_flag( "EFFECT_ACID_IMMUNE" ) ||
6252 worn_with_flag( "ACID_IMMUNE" );
6253 case DT_STAB:
6254 return has_effect_with_flag( "EFFECT_STAB_IMMUNE" ) ||
6255 worn_with_flag( "STAB_IMMUNE" );
6256 case DT_BULLET:
6257 return has_effect_with_flag( "EFFECT_BULLET_IMMUNE" ) || worn_with_flag( "BULLET_IMMUNE" );
6258 case DT_HEAT:
6259 return has_trait( trait_M_SKIN2 ) ||
6261 has_effect_with_flag( "EFFECT_HEAT_IMMUNE" ) ||
6262 worn_with_flag( "HEAT_IMMUNE" );
6263 case DT_COLD:
6264 return has_effect_with_flag( "EFFECT_COLD_IMMUNE" ) ||
6265 worn_with_flag( "COLD_IMMUNE" );
6266 case DT_ELECTRIC:
6267 return has_active_bionic( bio_faraday ) ||
6268 worn_with_flag( "ELECTRIC_IMMUNE" ) ||
6270 has_effect_with_flag( "EFFECT_ELECTRIC_IMMUNE" );
6271 default:
6272 return true;
6273 }
6274}
static const trait_id trait_ACIDPROOF("ACIDPROOF")
static const trait_id trait_M_SKIN2("M_SKIN2")
static const bionic_id bio_faraday("bio_faraday")
@ AEP_RESIST_ELECTRICITY
Definition: enums.h:117

References AEP_RESIST_ELECTRICITY, bio_faraday, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, has_active_bionic(), has_artifact_with(), Creature::has_effect_with_flag(), has_trait(), trait_ACIDPROOF, trait_M_SKIN2, trait_M_SKIN3, and worn_with_flag().

Referenced by player::immune_to(), is_elec_immune(), and is_immune_effect().

◆ is_immune_effect()

bool Character::is_immune_effect ( const efftype_id eff) const
overridevirtual

Returns true if the player is immune to this kind of effect.

Implements Creature.

Definition at line 6211 of file character.cpp.

6212{
6213 if( eff == effect_downed ) {
6215 } else if( eff == effect_onfire ) {
6216 return is_immune_damage( DT_HEAT );
6217 } else if( eff == effect_deaf ) {
6219 has_bionic( bio_ears ) ||
6221 } else if( eff == effect_corroding ) {
6223 } else if( eff == effect_nausea ) {
6225 } else if( eff == effect_bleed ) {
6226 // Ugly, it was badly implemented and should be a flag
6227 return mutation_value( "bleed_resist" ) > 0.0f;
6228 }
6229
6230 return false;
6231}
static const trait_id trait_SLIMY("SLIMY")
static const trait_id trait_LEG_TENT_BRACE("LEG_TENT_BRACE")
static const trait_id trait_STRONGSTOMACH("STRONGSTOMACH")
static const itype_id itype_rm13_armor_on("rm13_armor_on")
static const efftype_id effect_corroding("corroding")
static const trait_id trait_VISCOUS("VISCOUS")
static const std::string flag_PARTIAL_DEAF("PARTIAL_DEAF")
static const efftype_id effect_nausea("nausea")
double footwear_factor() const
Returns 1 if the player is wearing something on both feet, .5 if on one, and 0 if on neither.
Definition: character.cpp:8949
bool is_throw_immune() const
Returns true if the player is immune to throws.

References bio_ears, DT_ACID, DT_HEAT, effect_bleed, effect_corroding, effect_deaf, effect_downed, effect_nausea, effect_onfire, flag_DEAF(), flag_PARTIAL_DEAF(), footwear_factor(), has_bionic(), has_trait(), is_immune_damage(), is_throw_immune(), is_wearing(), itype_rm13_armor_on, mutation_value(), trait_LEG_TENT_BRACE, trait_SLIMY, trait_STRONGSTOMACH, trait_VISCOUS, and worn_with_flag().

Referenced by sounds::process_sound_markers().

◆ is_immune_field()

bool Character::is_immune_field ( const field_type_id ) const
overridevirtual

Returns true if we are immune to the field type with the given fid.

Does not handle intensity, so this function should only be called through is_dangerous_field().

Reimplemented from Creature.

Definition at line 6165 of file character.cpp.

6166{
6167 // Obviously this makes us invincible
6168 if( has_trait( trait_DEBUG_NODMG ) ) {
6169 return true;
6170 }
6171 // Check to see if we are immune
6172 const field_type &ft = fid.obj();
6173 for( const trait_id &t : ft.immunity_data_traits ) {
6174 if( has_trait( t ) ) {
6175 return true;
6176 }
6177 }
6178 bool immune_by_body_part_resistance = !ft.immunity_data_body_part_env_resistance.empty();
6179 for( const std::pair<body_part, int> &fide : ft.immunity_data_body_part_env_resistance ) {
6180 immune_by_body_part_resistance = immune_by_body_part_resistance &&
6181 get_env_resist( convert_bp( fide.first ).id() ) >= fide.second;
6182 }
6183 if( immune_by_body_part_resistance ) {
6184 return true;
6185 }
6186 if( ft.has_elec ) {
6187 return is_elec_immune();
6188 }
6189 if( ft.has_fire ) {
6191 }
6192 if( ft.has_acid ) {
6193 return !is_on_ground() && get_env_resist( bodypart_id( "foot_l" ) ) >= 15 &&
6194 get_env_resist( bodypart_id( "foot_r" ) ) >= 15 &&
6195 get_env_resist( bodypart_id( "leg_l" ) ) >= 15 &&
6196 get_env_resist( bodypart_id( "leg_r" ) ) >= 15 &&
6197 get_armor_type( DT_ACID, bodypart_id( "foot_l" ) ) >= 5 &&
6198 get_armor_type( DT_ACID, bodypart_id( "foot_r" ) ) >= 5 &&
6199 get_armor_type( DT_ACID, bodypart_id( "leg_l" ) ) >= 5 &&
6200 get_armor_type( DT_ACID, bodypart_id( "leg_r" ) ) >= 5;
6201 }
6202 // If we haven't found immunity yet fall up to the next level
6203 return Creature::is_immune_field( fid );
6204}
static const bionic_id bio_heatsink("bio_heatsink")
bool is_elec_immune() const override
Returns true is the player is protected from electric shocks.
Definition: character.cpp:6206
bool is_on_ground() const override
Returns true if the player is knocked over or has broken legs.
Definition: character.cpp:962
int get_env_resist(bodypart_id bp) const override
Returns overall env_resist on a body_part.
Definition: character.cpp:7147
virtual bool is_immune_field(const field_type_id &) const
Returns true if we are immune to the field type with the given fid.
Definition: creature.h:325
std::vector< trait_id > immunity_data_traits
Definition: field_type.h:172
bool has_elec
Definition: field_type.h:164
bool has_acid
Definition: field_type.h:163
bool has_fire
Definition: field_type.h:162
std::vector< std::pair< body_part, int > > immunity_data_body_part_env_resistance
Definition: field_type.h:173

References bio_heatsink, convert_bp(), DT_ACID, get_armor_type(), get_env_resist(), field_type::has_acid, has_active_bionic(), field_type::has_elec, field_type::has_fire, has_trait(), string_id< T >::id(), field_type::immunity_data_body_part_env_resistance, field_type::immunity_data_traits, is_elec_immune(), Creature::is_immune_field(), is_on_ground(), is_wearing(), itype_rm13_armor_on, int_id< T >::obj(), and trait_DEBUG_NODMG.

◆ is_invisible()

bool Character::is_invisible ( ) const

Definition at line 6364 of file character.cpp.

6365{
6366 return (
6371 );
6372}
static const std::string flag_EFFECT_INVISIBLE("EFFECT_INVISIBLE")
static const trait_id trait_DEBUG_CLOAK("DEBUG_CLOAK")
bool is_wearing_active_optcloak() const
Returns true if the player is wearing an active optical cloak.
Definition: character.cpp:3834
@ AEP_INVISIBLE
Definition: enums.h:110

References AEP_INVISIBLE, flag_EFFECT_INVISIBLE(), has_artifact_with(), Creature::has_effect_with_flag(), has_trait(), is_wearing_active_optcloak(), and trait_DEBUG_CLOAK.

Referenced by visibility().

◆ is_limb_broken()

bool Character::is_limb_broken ( const bodypart_id limb) const

◆ is_limb_disabled()

bool Character::is_limb_disabled ( const bodypart_id limb) const

Returns true if the limb is disabled(12.5% or less hp)

Definition at line 1320 of file character.cpp.

1321{
1322 return get_part_hp_cur( limb ) <= get_part_hp_max( limb ) * .125;
1323}

References Creature::get_part_hp_cur(), and Creature::get_part_hp_max().

Referenced by get_working_arm_count().

◆ is_limb_hindered()

bool Character::is_limb_hindered ( hp_part  limb) const

Returns true if the limb is hindered(40% or less hp)

◆ is_max_power()

bool Character::is_max_power ( ) const

Definition at line 2007 of file character.cpp.

2008{
2009 return power_level >= max_power_level;
2010}

References max_power_level, and power_level.

Referenced by feed_furnace_with().

◆ is_mounted()

bool Character::is_mounted ( ) const

Definition at line 1143 of file character.cpp.

1144{
1146}

References effect_riding, Creature::has_effect(), and mounted_creature.

Referenced by activate_bionic(), cata_event_dispatch::avatar_moves(), best_nearby_lifting_assist(), iuse::blood_draw(), iuse::boltcutters(), iuse::burrow(), can_install_bionics(), map::can_move_furniture(), cauterize_actor::can_use(), enzlave_actor::can_use(), musical_instrument_actor::can_use(), install_bionic_actor::can_use(), repair_item_actor::can_use_tool(), player::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), debug_menu::character_edit_menu(), check_mount_will_move(), iuse::chop_logs(), iuse::chop_tree(), iuse::clear_rubble(), iuse::craft(), iuse::crowbar(), iuse::cut_log_into_planks(), npc::die(), iuse::dig(), iuse::dig_channel(), iuse::disassemble(), dismount(), game::do_turn(), iuse::einktabletpc(), game::examine(), iuse::fill_pit(), player::fire_gun(), iuse::fish_trap(), iuse::fishing_rod(), iuse::gun_repair(), ranged::gunmode_checks_weapon(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), game::handle_action(), has_charges(), avatar::invoke_item(), iuse::jackhammer(), iuse::ladder(), player::list_ammo(), iuse::lumber(), iuse::makemound(), iuse::meditate(), melee_attack(), iuse::mind_splicer(), mine_activity(), iuse::mop(), avatar_action::move(), npc::move_to(), game::npc_menu(), game::on_move_effects(), overmap_sight_range(), iuse::oxytorch(), perform_technique(), iuse::pickaxe(), npc::place_on_map(), game::place_player(), game::place_player_overmap(), avatar_action::plthrow(), iuse::portable_game(), iuse::portal(), game::prompt_dangerous_tile(), recalc_sight_limits(), player::reset_stats(), iuse::rpgdie(), run_cost(), avatar::set_movement_mode(), iuse::shavekit(), iuse::siphon(), sleep(), smash(), store(), avatar_action::swim(), swim_speed(), iuse::teleport(), player::throw_item(), throw_range(), trapfunc::tripwire(), iuse::unfold_generic(), unfold_vehicle_iuse::use(), pick_lock_actor::use(), deploy_furn_actor::use(), cauterize_actor::use(), enzlave_actor::use(), musical_instrument_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), sew_advanced_actor::use(), weigh_self_actor::use(), use_charges(), game::vertical_move(), iuse::vibe(), game::walk_move(), iuse::wash_hard_items(), wash_items(), iuse::wash_soft_items(), iuse::water_purifier(), weight_capacity(), and npc::worker_downtime().

◆ is_on_ground()

bool Character::is_on_ground ( ) const
overridevirtual

Returns true if the player is knocked over or has broken legs.

Implements Creature.

Definition at line 962 of file character.cpp.

963{
965}

References effect_downed, get_working_leg_count(), and Creature::has_effect().

Referenced by is_immune_field(), map::player_in_field(), and game::walk_move().

◆ is_quiet()

bool Character::is_quiet ( ) const

Returns true if the player has quiet melee attacks.

Definition at line 1182 of file martialarts.cpp.

1183{
1184 return search_ma_buff_effect( *effects, []( const ma_buff & b, const effect & ) {
1185 return b.is_quiet();
1186 } );
1187}

References b, Creature::effects, and search_ma_buff_effect().

Referenced by melee_attack().

◆ is_rad_immune()

bool Character::is_rad_immune ( ) const

Returns true if the player is protected from radiation.

Definition at line 6276 of file character.cpp.

6277{
6278 bool has_helmet = false;
6279 return ( is_wearing_power_armor( &has_helmet ) && has_helmet ) || worn_with_flag( "RAD_PROOF" );
6280}

References is_wearing_power_armor(), and worn_with_flag().

Referenced by irradiate(), and suffer_from_radiation().

◆ is_snuggling()

std::string Character::is_snuggling ( ) const

Checks to see if the player is using floor items to keep warm, and return the name of one such item if so.

Definition at line 9339 of file character.cpp.

9340{
9341 map &here = get_map();
9342 auto begin = here.i_at( pos() ).begin();
9343 auto end = here.i_at( pos() ).end();
9344
9345 if( in_vehicle ) {
9346 if( const cata::optional<vpart_reference> vp = here.veh_at( pos() ).part_with_feature( VPFLAG_CARGO,
9347 false ) ) {
9348 vehicle *const veh = &vp->vehicle();
9349 const int cargo = vp->part_index();
9350 if( !veh->get_items( cargo ).empty() ) {
9351 begin = veh->get_items( cargo ).begin();
9352 end = veh->get_items( cargo ).end();
9353 }
9354 }
9355 }
9356 const item *floor_armor = nullptr;
9357 int ticker = 0;
9358
9359 // If there are no items on the floor, return nothing
9360 if( begin == end ) {
9361 return "nothing";
9362 }
9363
9364 for( auto candidate = begin; candidate != end; ++candidate ) {
9365 if( !candidate->is_armor() ) {
9366 continue;
9367 } else if( candidate->volume() > 250_ml && candidate->get_warmth() > 0 &&
9368 ( candidate->covers( bp_torso ) || candidate->covers( bp_leg_l ) ||
9369 candidate->covers( bp_leg_r ) ) ) {
9370 floor_armor = &*candidate;
9371 ticker++;
9372 }
9373 }
9374
9375 if( ticker == 0 ) {
9376 return "nothing";
9377 } else if( ticker == 1 ) {
9378 return floor_armor->type_name();
9379 } else if( ticker > 1 ) {
9380 return "many";
9381 }
9382
9383 return "nothing";
9384}
bool in_vehicle
Definition: character.h:1519
bool empty() const
Definition: item_stack.cpp:15

References item_stack::begin(), bp_leg_l, bp_leg_r, bp_torso, item_stack::empty(), item_stack::end(), vehicle::get_items(), get_map(), map::i_at(), in_vehicle, pos(), item::type_name(), map::veh_at(), vehicle::vehicle(), and VPFLAG_CARGO.

Referenced by fall_asleep().

◆ is_throw_immune()

bool Character::is_throw_immune ( ) const

Returns true if the player is immune to throws.

Definition at line 1176 of file martialarts.cpp.

1177{
1178 return search_ma_buff_effect( *effects, []( const ma_buff & b, const effect & ) {
1179 return b.is_throw_immune();
1180 } );
1181}

References b, Creature::effects, and search_ma_buff_effect().

Referenced by mattack::bio_op_takedown(), mattack::grab(), is_immune_effect(), mattack::thrown_by_judo(), and game::update_stair_monsters().

◆ is_visible_in_range()

bool Character::is_visible_in_range ( const Creature critter,
int  range 
) const
private

Check whether the other creature is in range and can be seen by this creature.

Parameters
critterCreature to check for visibility
rangeThe maximal distance (rl_dist), creatures at this distance or less are included.

Definition at line 10231 of file character.cpp.

10232{
10233 return sees( critter ) && rl_dist( pos(), critter.pos() ) <= range;
10234}

References Creature::pos(), pos(), rl_dist(), and sees().

◆ is_warm()

bool Character::is_warm ( ) const
overridevirtual

Reimplemented from Creature.

Definition at line 508 of file character.cpp.

509{
510 // TODO: is there a mutation (plant?) that makes a npc not warm blooded?
511 return true;
512}

◆ is_waterproof()

bool Character::is_waterproof ( const body_part_set parts) const

Definition at line 9009 of file character.cpp.

9010{
9011 return covered_with_flag( "WATERPROOF", parts );
9012}
bool covered_with_flag(const std::string &flag, const body_part_set &parts) const
Definition: character.cpp:8986

References covered_with_flag().

Referenced by drench().

◆ is_weak_to_water()

bool Character::is_weak_to_water ( ) const

Definition at line 414 of file mutation.cpp.

415{
416 for( const trait_id &mut : get_mutations() ) {
417 if( mut.obj().weakness_to_water > 0 ) {
418 return true;
419 }
420 }
421 return false;
422}

References get_mutations().

Referenced by drench().

◆ is_wearing() [1/2]

bool Character::is_wearing ( const item itm) const

◆ is_wearing() [2/2]

bool Character::is_wearing ( const itype_id it) const

Returns true if the player is wearing an item of this type.

Definition at line 3253 of file character.cpp.

3254{
3255 for( auto &i : worn ) {
3256 if( i.typeId() == it ) {
3257 return true;
3258 }
3259 }
3260 return false;
3261}

References worn.

◆ is_wearing_active_optcloak()

bool Character::is_wearing_active_optcloak ( ) const

Returns true if the player is wearing an active optical cloak.

Definition at line 3834 of file character.cpp.

3835{
3836 for( auto &w : worn ) {
3837 if( w.active && w.has_flag( flag_ACTIVE_CLOAKING ) ) {
3838 return true;
3839 }
3840 }
3841 return false;
3842}
static const std::string flag_ACTIVE_CLOAKING("ACTIVE_CLOAKING")

References flag_ACTIVE_CLOAKING(), and worn.

Referenced by player::basic_symbol_color(), and is_invisible().

◆ is_wearing_active_power_armor()

bool Character::is_wearing_active_power_armor ( ) const

Returns true if the character is wearing active power.

Definition at line 3824 of file character.cpp.

3825{
3826 for( const auto &w : worn ) {
3827 if( w.has_flag( flag_POWERARMOR_EXO ) && w.active ) {
3828 return true;
3829 }
3830 }
3831 return false;
3832}

References flag_POWERARMOR_EXO(), and worn.

◆ is_wearing_helmet()

bool Character::is_wearing_helmet ( ) const

Returns true if the character is wearing something occupying the helmet slot.

Definition at line 8912 of file character.cpp.

8913{
8914 for( const item &i : worn ) {
8915 if( i.covers( bp_head ) && !i.has_flag( flag_HELMET_COMPAT ) && !i.has_flag( flag_SKINTIGHT ) &&
8916 !i.has_flag( flag_PERSONAL ) && !i.has_flag( flag_AURA ) && !i.has_flag( flag_SEMITANGIBLE ) &&
8917 !i.has_flag( flag_OVERSIZE ) ) {
8918 return true;
8919 }
8920 }
8921 return false;
8922}

References bp_head, flag_AURA(), flag_HELMET_COMPAT(), flag_OVERSIZE(), flag_PERSONAL(), flag_SEMITANGIBLE(), flag_SKINTIGHT(), and worn.

Referenced by can_wear().

◆ is_wearing_on_bp()

bool Character::is_wearing_on_bp ( const itype_id it,
const bodypart_id bp 
) const

Returns true if the player is wearing the item on the given body part.

Definition at line 3263 of file character.cpp.

3264{
3265 for( auto &i : worn ) {
3266 if( i.typeId() == it && i.covers( bp->token ) ) {
3267 return true;
3268 }
3269 }
3270 return false;
3271}

References worn.

Referenced by shoe_type_count().

◆ is_wearing_power_armor()

bool Character::is_wearing_power_armor ( bool *  hasHelmet = nullptr) const

Returns true if the character is wearing power armor.

Definition at line 3799 of file character.cpp.

3800{
3801 bool result = false;
3802 for( auto &elem : worn ) {
3803 if( !elem.is_power_armor() ) {
3804 continue;
3805 }
3806 if( elem.has_flag( flag_POWERARMOR_EXO ) ) {
3807 result = true;
3808 if( hasHelmet == nullptr ) {
3809 // found power armor, helmet not requested, cancel loop
3810 return true;
3811 }
3812 }
3813 // found power armor, continue search for helmet
3814 if( elem.covers( bp_head ) ) {
3815 if( hasHelmet != nullptr ) {
3816 *hasHelmet = true;
3817 }
3818 return true;
3819 }
3820 }
3821 return result;
3822}

References bp_head, flag_POWERARMOR_EXO(), and worn.

Referenced by can_wear(), irradiate(), is_rad_immune(), power_rating(), and suffer_from_radiation().

◆ is_wearing_shoes()

bool Character::is_wearing_shoes ( const side which_side = side::BOTH) const

Returns true if the player is wearing something on their feet that is not SKINTIGHT.

Definition at line 8883 of file character.cpp.

8884{
8885 bool left = true;
8886 bool right = true;
8887 if( which_side == side::LEFT || which_side == side::BOTH ) {
8888 left = false;
8889 for( const item &worn_item : worn ) {
8890 if( worn_item.covers( bp_foot_l ) && !worn_item.has_flag( flag_BELTED ) &&
8891 !worn_item.has_flag( flag_PERSONAL ) && !worn_item.has_flag( flag_AURA ) &&
8892 !worn_item.has_flag( flag_SEMITANGIBLE ) && !worn_item.has_flag( flag_SKINTIGHT ) ) {
8893 left = true;
8894 break;
8895 }
8896 }
8897 }
8898 if( which_side == side::RIGHT || which_side == side::BOTH ) {
8899 right = false;
8900 for( const item &worn_item : worn ) {
8901 if( worn_item.covers( bp_foot_r ) && !worn_item.has_flag( flag_BELTED ) &&
8902 !worn_item.has_flag( flag_PERSONAL ) && !worn_item.has_flag( flag_AURA ) &&
8903 !worn_item.has_flag( flag_SEMITANGIBLE ) && !worn_item.has_flag( flag_SKINTIGHT ) ) {
8904 right = true;
8905 break;
8906 }
8907 }
8908 }
8909 return ( left && right );
8910}

References BOTH, bp_foot_l, bp_foot_r, flag_AURA(), flag_BELTED(), flag_PERSONAL(), flag_SEMITANGIBLE(), flag_SKINTIGHT(), LEFT, left, RIGHT, right, and worn.

Referenced by can_wear(), rooted_message(), and suffer_from_other_mutations().

◆ is_wielding()

◆ is_worn()

◆ item_encumb()

void Character::item_encumb ( char_encumbrance_data vals,
const item new_item 
) const
protected

Applies encumbrance from items only If new_item is not null, then calculate under the asumption that it is added to existing work items.

Definition at line 3974 of file character.cpp.

3975{
3976
3977 // reset all layer data
3978 vals = char_encumbrance_data();
3979
3980 // Figure out where new_item would be worn
3981 std::list<item>::const_iterator new_item_position = worn.end();
3982 if( !new_item.is_null() ) {
3983 // const_cast required to work around g++-4.8 library bug
3984 // see the commit that added this comment to understand why
3985 new_item_position =
3986 const_cast<Character *>( this )->position_to_wear_new_item( new_item );
3987 }
3988
3989 // Track highest layer observed so far so we can penalize out-of-order
3990 // items
3991 std::array<layer_level, num_bp> highest_layer_so_far;
3992 std::fill( highest_layer_so_far.begin(), highest_layer_so_far.end(),
3994
3995 for( auto w_it = worn.begin(); w_it != worn.end(); ++w_it ) {
3996 if( w_it == new_item_position ) {
3997 layer_item( vals, new_item, highest_layer_so_far, *this );
3998 }
3999 layer_item( vals, *w_it, highest_layer_so_far, *this );
4000 }
4001
4002 if( worn.end() == new_item_position && !new_item.is_null() ) {
4003 layer_item( vals, new_item, highest_layer_so_far, *this );
4004 }
4005
4006 // make sure values are sane
4007 for( const body_part bp : all_body_parts ) {
4008 encumbrance_data &elem = vals.elems[bp];
4009
4010 elem.armor_encumbrance = std::max( 0, elem.armor_encumbrance );
4011
4012 // Add armor and layering penalties for the final values
4013 elem.encumbrance += elem.armor_encumbrance + elem.layer_penalty;
4014 }
4015}
static void layer_item(char_encumbrance_data &vals, const item &it, std::array< layer_level, num_bp > &highest_layer_so_far, const Character &c)
Definition: character.cpp:3757
std::list< item >::iterator position_to_wear_new_item(const item &new_item)
Return the position in the worn list where new_item would be put by default.
Definition: character.cpp:3945
@ PERSONAL_LAYER
Definition: enums.h:216
FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t< Char > &fill)
std::array< encumbrance_data, num_bp > elems

References all_body_parts, encumbrance_data::armor_encumbrance, char_encumbrance_data::elems, encumbrance_data::encumbrance, detail::fill(), item::is_null(), layer_item(), encumbrance_data::layer_penalty, PERSONAL_LAYER, position_to_wear_new_item(), and worn.

Referenced by calc_encumbrance().

◆ item_handling_cost()

int Character::item_handling_cost ( const item it,
bool  penalties = true,
int  base_cost = INVENTORY_HANDLING_PENALTY 
) const

Calculate (but do not deduct) the number of moves required when handling (e.g.

storing, drawing etc.) an item

Parameters
itItem to calculate handling cost for
penaltiesWhether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered.
base_costCost due to storage type.
Returns
cost in moves ranging from 0 to MAX_HANDLING_COST

Definition at line 7586 of file character.cpp.

7587{
7588 int mv = base_cost;
7589 if( penalties ) {
7590 // 40 moves per liter, up to 200 at 5 liters
7591 mv += std::min( 200, it.volume() / 20_ml );
7592 }
7593
7594 if( weapon.typeId() == itype_e_handcuffs ) {
7595 mv *= 4;
7596 } else if( penalties && has_effect( effect_grabbed ) ) {
7597 mv *= 2;
7598 }
7599
7600 // For single handed items use the least encumbered hand
7601 if( it.is_two_handed( *this ) ) {
7602 mv += encumb( bp_hand_l ) + encumb( bp_hand_r );
7603 } else {
7604 mv += std::min( encumb( bp_hand_l ), encumb( bp_hand_r ) );
7605 }
7606
7607 return std::min( std::max( mv, 0 ), MAX_HANDLING_COST );
7608}
static const itype_id itype_e_handcuffs("e_handcuffs")
static constexpr int MAX_HANDLING_COST

References bp_hand_l, bp_hand_r, effect_grabbed, encumb(), Creature::has_effect(), item::is_two_handed(), itype_e_handcuffs, MAX_HANDLING_COST, item::typeId(), item::volume(), and weapon.

Referenced by dispose_item(), npc::dispose_item(), player::item_reload_cost(), item_store_cost(), item_wear_cost(), mill_activate(), mill_load_food(), avatar_action::plthrow(), iexamine::quern_examine(), smoker_activate(), smoker_load_food(), iexamine::smoker_options(), player::unload(), avatar::wield(), and player::wield_contents().

◆ item_store_cost()

int Character::item_store_cost ( const item it,
const item container,
bool  penalties = true,
int  base_cost = INVENTORY_HANDLING_PENALTY 
) const

Calculate (but do not deduct) the number of moves required when storing an item in a container.

Parameters
itItem to calculate storage cost for
containerContainer to store item in
penaltiesWhether item volume and temporary effects (e.g. GRABBED, DOWNED) should be considered.
base_costCost due to storage type.
Returns
cost in moves ranging from 0 to MAX_HANDLING_COST
Pistol decreases time taken to store a pistol Smg decreases time taken to store an SMG Rifle decreases time taken to store a rifle Shotgun decreases time taken to store a shotgun Launcher decreases time taken to store a launcher Stabbing decreases time taken to store a stabbing weapon Cutting decreases time taken to store a cutting weapon Bashing decreases time taken to store a bashing weapon

Definition at line 7610 of file character.cpp.

7612{
7613 /** @EFFECT_PISTOL decreases time taken to store a pistol */
7614 /** @EFFECT_SMG decreases time taken to store an SMG */
7615 /** @EFFECT_RIFLE decreases time taken to store a rifle */
7616 /** @EFFECT_SHOTGUN decreases time taken to store a shotgun */
7617 /** @EFFECT_LAUNCHER decreases time taken to store a launcher */
7618 /** @EFFECT_STABBING decreases time taken to store a stabbing weapon */
7619 /** @EFFECT_CUTTING decreases time taken to store a cutting weapon */
7620 /** @EFFECT_BASHING decreases time taken to store a bashing weapon */
7621 int lvl = get_skill_level( it.is_gun() ? it.gun_skill() : it.melee_skill() );
7622 return item_handling_cost( it, penalties, base_cost ) / ( ( lvl + 10.0f ) / 10.0f );
7623}

References get_skill_level(), item::gun_skill(), item::is_gun(), item_handling_cost(), and item::melee_skill().

Referenced by dispose_item(), npc::dispose_item(), and player::store().

◆ item_wear_cost()

int Character::item_wear_cost ( const item it) const

Calculate (but do not deduct) the number of moves required to wear an item.

Definition at line 7625 of file character.cpp.

7626{
7627 double mv = item_handling_cost( it );
7628
7629 switch( it.get_layer() ) {
7630 case PERSONAL_LAYER:
7631 break;
7632
7633 case UNDERWEAR_LAYER:
7634 mv *= 1.5;
7635 break;
7636
7637 case REGULAR_LAYER:
7638 break;
7639
7640 case WAIST_LAYER:
7641 case OUTER_LAYER:
7642 mv /= 1.5;
7643 break;
7644
7645 case BELTED_LAYER:
7646 mv /= 2.0;
7647 break;
7648
7649 case AURA_LAYER:
7650 break;
7651
7652 default:
7653 break;
7654 }
7655
7656 mv *= std::max( it.get_encumber( *this ) / 10.0, 1.0 );
7657
7658 return mv;
7659}
layer_level get_layer() const
Returns clothing layer for item.
Definition: item.cpp:5719
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224

References AURA_LAYER, BELTED_LAYER, item::get_encumber(), item::get_layer(), item_handling_cost(), OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by dispose_item(), and wear_item().

◆ item_with_best_of_quality()

item & Character::item_with_best_of_quality ( const quality_id qid)

Returns the item in the player's inventory with the highest of the specified quality.

Definition at line 10015 of file character.cpp.

10016{
10017 int maxq = max_quality( qid );
10018 auto items_with_quality = items_with( [qid]( const item & it ) {
10019 return it.has_quality( qid );
10020 } );
10021 for( item *it : items_with_quality ) {
10022 if( it->get_quality( qid ) == maxq ) {
10023 return *it;
10024 }
10025 }
10026 return null_item_reference();
10027}
int get_quality(const quality_id &id) const
Definition: item.cpp:5266

References item::get_quality(), visitable< T >::has_quality(), visitable< Character >::items_with(), visitable< Character >::max_quality(), and null_item_reference().

◆ item_worn_with_flag()

const item * Character::item_worn_with_flag ( const std::string &  flag,
const bodypart_id bp = bodypart_str_id::NULL_ID() 
) const

Returns the first worn item with a given flag.

Definition at line 3281 of file character.cpp.

3282{
3283 const item *it_with_flag = nullptr;
3284 for( const item &it : worn ) {
3285 if( it.has_flag( flag ) && ( bp == bodypart_str_id::NULL_ID() ||
3286 it.covers( bp->token ) ) ) {
3287 it_with_flag = &it;
3288 break;
3289 }
3290 }
3291 return it_with_flag;
3292}

References string_id< body_part_type >::NULL_ID(), and worn.

Referenced by burn_fuel().

◆ knows_trap()

bool Character::knows_trap ( const tripoint pos) const

Definition at line 10255 of file character.cpp.

10256{
10257 const tripoint p = get_map().getabs( pos );
10258 return known_traps.count( p ) > 0;
10259}

References get_map(), map::getabs(), known_traps, and pos().

Referenced by trap::can_see(), vehicle::handle_trap(), and player::search_surroundings().

◆ leak_level()

int Character::leak_level ( const std::string &  flag) const

Definition at line 1968 of file suffer.cpp.

1969{
1970 int leak_level = 0;
1971 leak_level = inv.leak_level( flag );
1972 return leak_level;
1973}
int leak_level(const std::string &flag) const
Definition: suffer.cpp:1968
int leak_level(const std::string &flag) const
Definition: inventory.cpp:896

References inv, leak_level(), and inventory::leak_level().

Referenced by iexamine::autodoc(), iuse::geiger(), leak_level(), and suffer_from_radiation().

◆ limb_color()

nc_color Character::limb_color ( const bodypart_id bp,
bool  bleed,
bool  bite,
bool  infect 
) const

Definition at line 6072 of file character.cpp.

6073{
6074 if( bp == bodypart_id( "num_bp" ) ) {
6075 return c_light_gray;
6076 }
6077 const body_part bp_token = bp->token;
6078 int color_bit = 0;
6079 nc_color i_color = c_light_gray;
6080 if( bleed && has_effect( effect_bleed, bp_token ) ) {
6081 color_bit += 1;
6082 }
6083 if( bite && has_effect( effect_bite, bp_token ) ) {
6084 color_bit += 10;
6085 }
6086 if( infect && has_effect( effect_infected, bp_token ) ) {
6087 color_bit += 100;
6088 }
6089 switch( color_bit ) {
6090 case 1:
6091 i_color = c_red;
6092 break;
6093 case 10:
6094 i_color = c_blue;
6095 break;
6096 case 100:
6097 i_color = c_green;
6098 break;
6099 case 11:
6100 i_color = c_magenta;
6101 break;
6102 case 101:
6103 i_color = c_yellow;
6104 break;
6105 }
6106
6107 return i_color;
6108}
#define c_magenta
Definition: color.h:25

References Creature::bleed(), c_blue, c_green, c_light_gray, c_magenta, c_red, c_yellow, effect_bite, effect_bleed, effect_infected, and Creature::has_effect().

Referenced by body_window(), draw_health_classic(), draw_limb2(), draw_limb_narrow(), draw_limb_wide(), and extended_description().

◆ load()

void Character::load ( const JsonObject data)
protected

Gather variables for saving.

These variables are common to both the avatar and NPCs.

Definition at line 387 of file savegame_json.cpp.

388{
390 Creature::load( data );
391
392 if( !data.read( "posx", position.x ) ) { // uh-oh.
393 debugmsg( "BAD PLAYER/NPC JSON: no 'posx'?" );
394 }
395 data.read( "posy", position.y );
396 if( !data.read( "posz", position.z ) && g != nullptr ) {
397 position.z = g->get_levz();
398 }
399 // stats
400 data.read( "str_cur", str_cur );
401 data.read( "str_max", str_max );
402 data.read( "dex_cur", dex_cur );
403 data.read( "dex_max", dex_max );
404 data.read( "int_cur", int_cur );
405 data.read( "int_max", int_max );
406 data.read( "per_cur", per_cur );
407 data.read( "per_max", per_max );
408
409 data.read( "str_bonus", str_bonus );
410 data.read( "dex_bonus", dex_bonus );
411 data.read( "per_bonus", per_bonus );
412 data.read( "int_bonus", int_bonus );
413 data.read( "omt_path", omt_path );
414
415 data.read( "base_age", init_age );
416 data.read( "base_height", init_height );
417
418 if( !data.read( "profession", prof ) || !prof.is_valid() ) {
419 // We are likely an older profession which has since been removed so just set to default.
420 // This is only cosmetic after game start.
422 }
423 data.read( "custom_profession", custom_profession );
424
425 // needs
426 data.read( "thirst", thirst );
427 data.read( "fatigue", fatigue );
428 data.read( "sleep_deprivation", sleep_deprivation );
429 data.read( "stored_calories", stored_calories );
430 data.read( "radiation", radiation );
431 data.read( "oxygen", oxygen );
432 data.read( "pkill", pkill );
433
434 data.read( "type_of_scent", type_of_scent );
435
436 if( data.has_array( "ma_styles" ) ) {
437 std::vector<matype_id> temp_styles;
438 data.read( "ma_styles", temp_styles );
439 bool temp_keep_hands_free = false;
440 data.read( "keep_hands_free", temp_keep_hands_free );
441 matype_id temp_selected_style;
442 data.read( "style_selected", temp_selected_style );
443 if( !temp_selected_style.is_valid() ) {
444 temp_selected_style = matype_id( "style_none" );
445 }
447 temp_styles, temp_selected_style, temp_keep_hands_free
448 ) );
449 } else {
450 data.read( "martial_arts_data", martial_arts_data );
451 }
452
453 JsonObject vits = data.get_object( "vitamin_levels" );
455 for( const std::pair<const vitamin_id, vitamin> &v : vitamin::all() ) {
456 if( vits.has_member( v.first.str() ) ) {
457 int lvl = vits.get_int( v.first.str() );
458 vitamin_levels[v.first] = clamp( lvl, v.first->min(), v.first->max() );
459 }
460 }
461 data.read( "consumption_history", consumption_history );
462 data.read( "activity", activity );
463 data.read( "destination_activity", destination_activity );
464 data.read( "stashed_outbounds_activity", stashed_outbounds_activity );
465 data.read( "stashed_outbounds_backlog", stashed_outbounds_backlog );
466 data.read( "backlog", backlog );
467 if( !backlog.empty() && !backlog.front().str_values.empty() && ( ( activity &&
468 activity.id() == activity_id( "ACT_FETCH_REQUIRED" ) ) || ( destination_activity &&
469 destination_activity.id() == activity_id( "ACT_FETCH_REQUIRED" ) ) ) ) {
470 requirement_data fetch_reqs;
471 data.read( "fetch_data", fetch_reqs );
472 const requirement_id req_id( backlog.front().str_values.back() );
473 requirement_data::save_requirement( fetch_reqs, req_id );
474 }
475 // npc activity on vehicles.
476 data.read( "activity_vehicle_part_index", activity_vehicle_part_index );
477 // health
478 data.read( "healthy", healthy );
479 data.read( "healthy_mod", healthy_mod );
480 data.read( "healed_24h", healed_total );
481
482 // status
483 temp_cur.fill( 5000 );
484 data.read( "temp_cur", temp_cur );
485
486 temp_conv.fill( 5000 );
487 data.read( "temp_conv", temp_conv );
488
489 frostbite_timer.fill( 0 );
490 data.read( "frostbite_timer", frostbite_timer );
491
492 body_wetness.fill( 0 );
493 data.read( "body_wetness", body_wetness );
494
495 //energy
496 data.read( "stim", stim );
497 data.read( "stamina", stamina );
498
499 data.read( "damage_bandaged", damage_bandaged );
500 data.read( "damage_disinfected", damage_disinfected );
501 data.read( "magic", magic );
502 JsonArray parray;
503
504 data.read( "underwater", underwater );
505
506 data.read( "traits", my_traits );
507 for( auto it = my_traits.begin(); it != my_traits.end(); ) {
508 const auto &tid = *it;
509 if( tid.is_valid() ) {
510 ++it;
511 } else {
512 debugmsg( "character %s has invalid trait %s, it will be ignored", name, tid.c_str() );
513 my_traits.erase( it++ );
514 }
515 }
516
517 data.read( "mutations", my_mutations );
518 for( auto it = my_mutations.begin(); it != my_mutations.end(); ) {
519 const trait_id &mid = it->first;
520 if( mid.is_valid() ) {
521 on_mutation_gain( mid );
522 cached_mutations.push_back( &mid.obj() );
523 ++it;
524 } else {
525 debugmsg( "character %s has invalid mutation %s, it will be ignored", name, mid.c_str() );
526 it = my_mutations.erase( it );
527 }
528 }
530
531 data.read( "my_bionics", *my_bionics );
532
533 for( auto &w : worn ) {
534 w.on_takeoff( *this );
535 }
536 worn.clear();
537 data.read( "worn", worn );
538 for( auto &w : worn ) {
539 on_item_wear( w );
540 }
541
542 if( data.has_array( "hp_cur" ) ) {
543 set_anatomy( anatomy_id( "human_anatomy" ) );
544 set_body();
545 std::array<int, 6> hp_cur;
546 data.read( "hp_cur", hp_cur );
547 std::array<int, 6> hp_max;
548 data.read( "hp_max", hp_max );
549 set_part_hp_max( bodypart_id( "head" ), hp_max[0] );
550 set_part_hp_cur( bodypart_id( "head" ), hp_cur[0] );
551
552 set_part_hp_max( bodypart_id( "torso" ), hp_max[1] );
553 set_part_hp_cur( bodypart_id( "torso" ), hp_cur[1] );
554
555 set_part_hp_max( bodypart_id( "arm_l" ), hp_max[2] );
556 set_part_hp_cur( bodypart_id( "arm_l" ), hp_cur[2] );
557
558 set_part_hp_max( bodypart_id( "arm_r" ), hp_max[3] );
559 set_part_hp_cur( bodypart_id( "arm_r" ), hp_cur[3] );
560
561 set_part_hp_max( bodypart_id( "leg_l" ), hp_max[4] );
562 set_part_hp_cur( bodypart_id( "leg_l" ), hp_cur[4] );
563
564 set_part_hp_max( bodypart_id( "leg_r" ), hp_max[5] );
565 set_part_hp_cur( bodypart_id( "leg_r" ), hp_cur[5] );
566 }
567
568
569 inv.clear();
570 if( data.has_member( "inv" ) ) {
571 JsonIn *invin = data.get_raw( "inv" );
572 inv.json_load_items( *invin );
573 }
574
576 data.read( "weapon", weapon );
577
578 data.read( "move_mode", move_mode );
579
580 if( has_effect( effect_riding ) ) {
581 int temp_id;
582 if( data.read( "mounted_creature", temp_id ) ) {
583 mounted_creature_id = temp_id;
584 mounted_creature = g->critter_tracker->from_temporary_id( temp_id );
585 } else {
586 mounted_creature = nullptr;
587 }
588 }
589
590 morale->load( data );
591 // Have to go through effects again, in case an effect gained a morale bonus
592 for( const auto &elem : *effects ) {
593 for( const std::pair<const bodypart_str_id, effect> &_effect_it : elem.second ) {
594 const effect &e = _effect_it.second;
596 }
597 }
598
599 _skills->clear();
600 for( const JsonMember member : data.get_object( "skills" ) ) {
601 member.read( ( *_skills )[skill_id( member.name() )] );
602 }
603
604 on_stat_change( "thirst", thirst );
605 on_stat_change( "stored_calories", stored_calories );
606 on_stat_change( "fatigue", fatigue );
607 on_stat_change( "sleep_deprivation", sleep_deprivation );
608 on_stat_change( "pkill", pkill );
609 on_stat_change( "perceived_pain", get_perceived_pain() );
612
613 assign( data, "power_level", power_level, false, 0_kJ );
614 assign( data, "max_power_level", max_power_level, false, 0_kJ );
615
616 // Bionic power should not be negative!
617 if( power_level < 0_J ) {
618 power_level = 0_J;
619 }
620
621 JsonArray overmap_time_array = data.get_array( "overmap_time" );
622 overmap_time.clear();
623 while( overmap_time_array.has_more() ) {
624 point_abs_omt pt;
625 overmap_time_array.read_next( pt );
626 time_duration tdr = 0_turns;
627 overmap_time_array.read_next( tdr );
628 overmap_time[pt] = tdr;
629 }
630 data.read( "stomach", stomach );
631 data.read( "automoveroute", auto_move_route );
632
633 known_traps.clear();
634 for( JsonObject pmap : data.get_array( "known_traps" ) ) {
635 pmap.allow_omitted_members();
636 const tripoint p( pmap.get_int( "x" ), pmap.get_int( "y" ), pmap.get_int( "z" ) );
637 const std::string t = pmap.get_string( "trap" );
638 known_traps.insert( trap_map::value_type( p, t ) );
639 }
640}
bool assign(const JsonObject &jo, const std::string &name, T &val, bool strict=false, T lo=std::numeric_limits< T >::lowest(), T hi=std::numeric_limits< T >::max())
Definition: assign.h:54
void on_stat_change(const std::string &stat, int value) override
Called when a stat is changed.
Definition: character.cpp:9920
std::map< vitamin_id, int > vitamin_levels
Current deficiency/excess quantity for each vitamin.
Definition: character.h:2134
int activity_vehicle_part_index
Definition: character.h:1568
void on_effect_int_change(const efftype_id &effect_type, int intensity, const bodypart_str_id &bp) override
Called when effect intensity has been changed.
Definition: character.cpp:9891
int oxygen
Definition: character.h:1538
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9863
void recalculate_size()
Recalculate size class of character.
Definition: mutation.cpp:246
int mounted_creature_id
Definition: character.h:1566
void set_body()
Definition: creature.cpp:1532
void set_part_hp_max(const bodypart_id &id, int set)
Definition: creature.cpp:1580
void load(const JsonObject &jsin)
bool has_more() const
Definition: json.cpp:484
bool read_next(T &t)
Definition: json.h:1113
Definition: json.h:177
Represents a member of a JsonObject.
Definition: json.h:1249
JsonObject get_object(const std::string &name) const
Definition: json.cpp:361
JsonArray get_array(const std::string &name) const
Definition: json.cpp:332
bool has_member(const std::string &name) const
Definition: json.cpp:181
JsonIn * get_raw(const std::string &name) const
Definition: json.cpp:241
int get_int(const std::string &name) const
Definition: json.cpp:282
bool has_array(const std::string &name) const
Definition: json.cpp:415
void allow_omitted_members() const
Definition: json.cpp:150
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:944
void json_load_items(JsonIn &jsin)
void clear()
Definition: inventory.cpp:237
This is a wrapper for implementing the pointer-to-implementation technique, see for example http://en...
Definition: pimpl.h:35
const char * c_str() const
Interface to the plain C-string of the id.
Definition: string_id.h:247
static const std::map< vitamin_id, vitamin > & all()
Get all currently loaded vitamins.
Definition: vitamin.cpp:98
std::string member
Definition: mapgen.cpp:402
static const efftype_id effect_riding("riding")
static void save_requirement(const requirement_data &req, const requirement_id &id=requirement_id::NULL_ID())
Store requirement data for future lookup.

References _skills, activity, activity_vehicle_part_index, vitamin::all(), JsonObject::allow_omitted_members(), assign(), auto_move_route, backlog, body_wetness, string_id< T >::c_str(), cached_mutations, clamp(), inventory::clear(), consumption_history, custom_profession, damage_bandaged, damage_disinfected, debugmsg, destination_activity, dex_bonus, dex_cur, dex_max, effect_riding, Creature::effects, fatigue, frostbite_timer, g, profession::generic(), JsonObject::get_array(), effect::get_bp(), effect::get_id(), JsonObject::get_int(), effect::get_intensity(), JsonObject::get_object(), Creature::get_perceived_pain(), JsonObject::get_raw(), JsonObject::has_array(), Creature::has_effect(), JsonObject::has_member(), JsonArray::has_more(), healed_total, healthy, healthy_mod, player_activity::id(), init_age, init_height, int_bonus, int_cur, int_max, inv, string_id< T >::is_valid(), inventory::json_load_items(), known_traps, Creature::load(), magic, martial_arts_data, matype_id, max_power_level, mapgen_defer::member, morale, mounted_creature, mounted_creature_id, move_mode, my_bionics, my_mutations, my_traits, name, string_id< T >::obj(), omt_path, on_effect_int_change(), on_item_wear(), on_mutation_gain(), on_stat_change(), overmap_time, oxygen, per_bonus, per_cur, per_max, pkill, position, power_level, prof, radiation, JsonObject::read(), JsonArray::read_next(), recalc_sight_limits(), recalculate_size(), reset_encumbrance(), requirement_data::save_requirement(), Creature::set_anatomy(), Creature::set_body(), Creature::set_part_hp_cur(), Creature::set_part_hp_max(), skill_id, sleep_deprivation, stamina, calendar::start_of_cataclysm, stashed_outbounds_activity, stashed_outbounds_backlog, stim, stomach, stored_calories, str_bonus, str_cur, str_max, temp_conv, temp_cur, thirst, type_of_scent, Creature::underwater, vitamin_levels, weapon, worn, tripoint::x, tripoint::y, and tripoint::z.

Referenced by monster::deserialize(), avatar::deserialize(), npc::deserialize(), and player::load().

◆ mabuff_armor_bonus()

int Character::mabuff_armor_bonus ( damage_type  type) const

Returns the armor bonus against given type from martial arts buffs.

Definition at line 1130 of file martialarts.cpp.

1131{
1132 int ret = 0;
1133 accumulate_ma_buff_effects( *effects, [&ret, type, this]( const ma_buff & b, const effect & d ) {
1134 ret += d.get_intensity() * b.armor_bonus( *this, type );
1135 } );
1136 return ret;
1137}
static void accumulate_ma_buff_effects(const C &container, F f)

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), cata::hash64_detail::ret, and type.

Referenced by passive_absorb_hit().

◆ mabuff_arpen_bonus()

int Character::mabuff_arpen_bonus ( damage_type  type) const

Returns the arpen bonus from martial arts buffs.

Definition at line 1122 of file martialarts.cpp.

1123{
1124 int ret = 0;
1125 accumulate_ma_buff_effects( *effects, [&ret, type, this]( const ma_buff & b, const effect & d ) {
1126 ret += d.get_intensity() * b.arpen_bonus( *this, type );
1127 } );
1128 return ret;
1129}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), cata::hash64_detail::ret, and type.

Referenced by roll_bash_damage(), roll_cut_damage(), and roll_stab_damage().

◆ mabuff_attack_cost_mult()

float Character::mabuff_attack_cost_mult ( ) const

Returns the multiplier on move cost of attacks.

Definition at line 1164 of file martialarts.cpp.

1165{
1166 float ret = 1.0f;
1167 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) {
1168 // This is correct, so that a 20% buff (1.2) plus a 20% buff (1.2)
1169 // becomes 1.4 instead of 2.4 (which would be a 240% buff)
1170 ret *= d.get_intensity() * ( b.bonuses.get_mult( *this,
1171 affected_stat::MOVE_COST ) - 1 ) + 1;
1172 } );
1173 return ret;
1174}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), MOVE_COST, and cata::hash64_detail::ret.

Referenced by attack_cost().

◆ mabuff_attack_cost_penalty()

int Character::mabuff_attack_cost_penalty ( ) const

Returns the flat penalty to move cost of attacks.

If negative, that's a bonus. Applied after multiplier.

Definition at line 1156 of file martialarts.cpp.

1157{
1158 int ret = 0;
1159 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) {
1160 ret += d.get_intensity() * b.bonuses.get_flat( *this, affected_stat::MOVE_COST );
1161 } );
1162 return ret;
1163}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), MOVE_COST, and cata::hash64_detail::ret.

Referenced by attack_cost().

◆ mabuff_block_bonus()

int Character::mabuff_block_bonus ( ) const

Returns the block bonus from martial arts buffs.

Definition at line 1106 of file martialarts.cpp.

1107{
1108 int ret = 0;
1109 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) {
1110 ret += d.get_intensity() * b.block_bonus( *this );
1111 } );
1112 return ret;
1113}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), and cata::hash64_detail::ret.

Referenced by block_hit().

◆ mabuff_damage_bonus()

int Character::mabuff_damage_bonus ( damage_type  type) const

Returns the flat damage bonus to given type from martial arts buffs, applied after the multiplier.

Definition at line 1148 of file martialarts.cpp.

1149{
1150 int ret = 0;
1151 accumulate_ma_buff_effects( *effects, [&ret, type, this]( const ma_buff & b, const effect & d ) {
1152 ret += d.get_intensity() * b.damage_bonus( *this, type );
1153 } );
1154 return ret;
1155}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), cata::hash64_detail::ret, and type.

Referenced by roll_bash_damage(), roll_cut_damage(), and roll_stab_damage().

◆ mabuff_damage_mult()

float Character::mabuff_damage_mult ( damage_type  type) const

Returns the damage multiplier to given type from martial arts buffs.

Definition at line 1138 of file martialarts.cpp.

1139{
1140 float ret = 1.f;
1141 accumulate_ma_buff_effects( *effects, [&ret, type, this]( const ma_buff & b, const effect & d ) {
1142 // This is correct, so that a 20% buff (1.2) plus a 20% buff (1.2)
1143 // becomes 1.4 instead of 2.4 (which would be a 240% buff)
1144 ret *= d.get_intensity() * ( b.damage_mult( *this, type ) - 1 ) + 1;
1145 } );
1146 return ret;
1147}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), cata::hash64_detail::ret, and type.

Referenced by roll_bash_damage(), roll_cut_damage(), and roll_stab_damage().

◆ mabuff_dodge_bonus()

float Character::mabuff_dodge_bonus ( ) const

Returns the dodge bonus from martial arts buffs.

Definition at line 1098 of file martialarts.cpp.

1099{
1100 float ret = 0;
1101 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) {
1102 ret += d.get_intensity() * b.dodge_bonus( *this );
1103 } );
1104 return ret;
1105}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), and cata::hash64_detail::ret.

Referenced by player::reset_stats().

◆ mabuff_speed_bonus()

int Character::mabuff_speed_bonus ( ) const

Returns the speed bonus from martial arts buffs.

Definition at line 1114 of file martialarts.cpp.

1115{
1116 int ret = 0;
1117 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) {
1118 ret += d.get_intensity() * b.speed_bonus( *this );
1119 } );
1120 return ret;
1121}

References accumulate_ma_buff_effects(), b, Creature::effects, effect::get_intensity(), and cata::hash64_detail::ret.

Referenced by player::recalc_speed_bonus().

◆ mabuff_tohit_bonus()

float Character::mabuff_tohit_bonus ( ) const

Returns the to hit bonus from martial arts buffs.

Definition at line 1090 of file martialarts.cpp.

1091{
1092 float ret = 0;
1093 accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & ) {
1094 ret += b.hit_bonus( *this );
1095 } );
1096 return ret;
1097}

References accumulate_ma_buff_effects(), b, Creature::effects, and cata::hash64_detail::ret.

Referenced by get_melee_hit_base().

◆ made_of()

bool Character::made_of ( const material_id m) const
overridevirtual

Implements Creature.

Definition at line 6328 of file character.cpp.

6329{
6330 // TODO: check for mutations that change this.
6331 return std::find( fleshy.begin(), fleshy.end(), m ) != fleshy.end();
6332}
static const std::vector< material_id > fleshy
Definition: character.h:770

References detail::find(), and fleshy.

◆ made_of_any()

bool Character::made_of_any ( const std::set< material_id > &  ms) const
overridevirtual

Implements Creature.

Definition at line 6333 of file character.cpp.

6334{
6335 // TODO: check for mutations that change this.
6336 return std::any_of( fleshy.begin(), fleshy.end(), [&ms]( const material_id & e ) {
6337 return ms.count( e );
6338 } );
6339}
constexpr scale ms
Definition: coordinates.h:30

References fleshy, and coords::ms.

◆ max_stored_kcal()

◆ meets_requirements()

bool Character::meets_requirements ( const item it,
const item context = item() 
) const

Checks whether the character meets overall requirements to be able to use the item.

Definition at line 3467 of file character.cpp.

3468{
3469 const auto &ctx = !context.is_null() ? context : it;
3471}
bool meets_stat_requirements(const item &it) const
Checks whether the character's stats meets the stats required by the item.
Definition: character.cpp:3459
bool meets_skill_requirements(const std::map< skill_id, int > &req, const item &context=item()) const
Checks whether the character's skills meet the required.
Definition: character.cpp:3445

References item::is_null(), meets_skill_requirements(), meets_stat_requirements(), itype::min_skills, and item::type.

Referenced by can_use(), gunmod_inventory_preset::get_denial(), and item::gun_range().

◆ meets_skill_requirements() [1/2]

bool Character::meets_skill_requirements ( const construction con) const

Checks whether the character's skills meet the required.

Definition at line 3451 of file character.cpp.

3452{
3453 return std::all_of( con.required_skills.begin(), con.required_skills.end(),
3454 [&]( const std::pair<skill_id, int> &pr ) {
3455 return get_skill_level( pr.first ) >= pr.second;
3456 } );
3457}
std::map< skill_id, int > required_skills
Skill->skill level mapping.
Definition: construction.h:69

References construction::required_skills.

◆ meets_skill_requirements() [2/2]

bool Character::meets_skill_requirements ( const std::map< skill_id, int > &  req,
const item context = item() 
) const

Checks whether the character's skills meet the required.

Definition at line 3445 of file character.cpp.

3447{
3448 return _skills->meets_skill_requirements( req, context );
3449}

References _skills.

Referenced by activity_handlers::build_do_turn(), player::can_decomp_learn(), find_base_construction(), player::get_learned_recipes(), meets_requirements(), and player_can_build().

◆ meets_stat_requirements()

bool Character::meets_stat_requirements ( const item it) const

Checks whether the character's stats meets the stats required by the item.

Definition at line 3459 of file character.cpp.

3460{
3461 return ( it.has_flag( flag_STR_DRAW ) || get_str() >= it.get_min_str() ) &&
3462 get_dex() >= it.type->min_dex &&
3463 get_int() >= it.type->min_int &&
3464 get_per() >= it.type->min_per;
3465}
static const std::string flag_STR_DRAW("STR_DRAW")

References flag_STR_DRAW(), get_dex(), get_int(), item::get_min_str(), get_per(), get_str(), item::has_flag(), itype::min_dex, itype::min_int, itype::min_per, and item::type.

Referenced by meets_requirements().

◆ melee_attack() [1/2]

void Character::melee_attack ( Creature t,
bool  allow_special 
)

Calls the to other melee_attack function with an empty technique id (meaning no specific technique should be used).

Definition at line 382 of file melee.cpp.

383{
384 static const matec_id no_technique_id( "" );
385 melee_attack( t, allow_special, no_technique_id );
386}

References melee_attack().

◆ melee_attack() [2/2]

void Character::melee_attack ( Creature t,
bool  allow_special,
const matec_id force_technique,
bool  allow_unarmed = true 
)

Sets up a melee attack and handles melee attack function calls.

Parameters
tCreature to attack
allow_specialwhether non-forced martial art technique or mutation attack should be possible with this attack.
force_techniquespecial technique to use in attack.
allow_unarmedalways uses the wielded weapon regardless of martialarts style
Melee reduces stamina cost of melee attacks

Definition at line 390 of file melee.cpp.

392{
394 int hit_spread = t.deal_melee_attack( this, hit_roll() );
395 if( !t.is_player() ) {
396 // TODO: Per-NPC tracking? Right now monster hit by either npc or player will draw aggro...
397 t.add_effect( effect_hit_by_player, 10_minutes ); // Flag as attacked by us for AI
398 }
399 if( is_mounted() ) {
400 auto mons = mounted_creature.get();
401 if( mons->has_flag( MF_RIDEABLE_MECH ) ) {
402 if( !mons->check_mech_powered() ) {
403 add_msg( m_bad, _( "The %s has dead batteries and will not move its arms." ),
404 mons->get_name() );
405 return;
406 }
407 if( mons->type->has_special_attack( "SMASH" ) && one_in( 3 ) ) {
408 add_msg( m_info, _( "The %s hisses as its hydraulic arm pumps forward!" ),
409 mons->get_name() );
410 mattack::smash_specific( mons, &t );
411 } else {
412 mons->use_mech_power( -2 );
413 mons->melee_attack( t );
414 }
415 mod_moves( -mons->type->attack_cost );
416 return;
417 }
418 }
419 item &cur_weapon = allow_unarmed ? used_weapon() : weapon;
420
421 if( cur_weapon.attack_cost() > attack_cost( cur_weapon ) * 20 ) {
422 add_msg( m_bad, _( "This weapon is too unwieldy to attack with!" ) );
423 return;
424 }
425
426 int move_cost = attack_cost( cur_weapon );
427
428 if( hit_spread < 0 ) {
429 int stumble_pen = stumble( *this, cur_weapon );
430 sfx::generate_melee_sound( pos(), t.pos(), false, false );
431 if( is_player() ) { // Only display messages if this is the player
432
433 if( one_in( 2 ) ) {
434 const std::string reason_for_miss = get_miss_reason();
435 if( !reason_for_miss.empty() ) {
436 add_msg( reason_for_miss );
437 }
438 }
439
440 if( can_miss_recovery( cur_weapon ) ) {
441 ma_technique tec = martial_arts_data->get_miss_recovery_tec( cur_weapon );
442 add_msg( _( tec.avatar_message ), t.disp_name() );
443 } else if( stumble_pen >= 60 ) {
444 add_msg( m_bad, _( "You miss and stumble with the momentum." ) );
445 } else if( stumble_pen >= 10 ) {
446 add_msg( _( "You swing wildly and miss." ) );
447 } else {
448 add_msg( _( "You miss." ) );
449 }
450 } else if( g->u.sees( *this ) ) {
451 if( stumble_pen >= 60 ) {
452 add_msg( _( "%s misses and stumbles with the momentum." ), name );
453 } else if( stumble_pen >= 10 ) {
454 add_msg( _( "%s swings wildly and misses." ), name );
455 } else {
456 add_msg( _( "%s misses." ), name );
457 }
458 }
459
460 // Practice melee and relevant weapon skill (if any) except when using CQB bionic
461 if( !has_active_bionic( bio_cqb ) ) {
462 melee_train( *this, 2, 5, cur_weapon );
463 }
464
465 // Cap stumble penalty, heavy weapons are quite weak already
466 move_cost += std::min( 60, stumble_pen );
467 if( martial_arts_data->has_miss_recovery_tec( cur_weapon ) ) {
468 move_cost /= 2;
469 }
470
471 // trigger martial arts on-miss effects
472 martial_arts_data->ma_onmiss_effects( *this );
473 } else {
475 // Remember if we see the monster at start - it may change
476 const bool seen = g->u.sees( t );
477 // Start of attacks.
478 const bool critical_hit = scored_crit( t.dodge_roll(), cur_weapon );
479 if( critical_hit ) {
481 }
483 roll_all_damage( critical_hit, d, false, cur_weapon );
484
485 const bool has_force_technique = !force_technique.str().empty();
486
487 // Pick one or more special attacks
488 matec_id technique_id;
489 if( allow_special && !has_force_technique ) {
490 technique_id = pick_technique( t, cur_weapon, critical_hit, false, false );
491 } else if( has_force_technique ) {
492 technique_id = force_technique;
493 } else {
494 technique_id = tec_none;
495 }
496
497 // if you have two broken arms you aren't doing any martial arts
498 // and your hits are not going to hurt very much
499 if( get_working_arm_count() < 1 ) {
500 technique_id = tec_none;
501 d.mult_damage( 0.1 );
502 }
503 // polearms and pikes (but not spears) do less damage to adjacent targets
504 if( cur_weapon.reach_range( *this ) > 1 && !reach_attacking &&
505 cur_weapon.has_flag( "POLEARM" ) ) {
506 d.mult_damage( 0.7 );
507 }
508
509 const ma_technique &technique = technique_id.obj();
510
511 // Handles effects as well; not done in melee_affect_*
512 if( technique.id != tec_none ) {
513 perform_technique( technique, t, d, move_cost );
514 }
515
516 // Proceed with melee attack.
517 if( !t.is_dead_state() ) {
518 // Handles speed penalties to monster & us, etc
519 std::string specialmsg = melee_special_effects( t, d, cur_weapon );
520
521 // gets overwritten with the dealt damage values
522 dealt_damage_instance dealt_dam;
523 dealt_damage_instance dealt_special_dam;
524 if( allow_special ) {
525 perform_special_attacks( t, dealt_special_dam );
526 }
527 t.deal_melee_hit( this, hit_spread, critical_hit, d, dealt_dam );
528 if( dealt_special_dam.type_damage( DT_CUT ) > 0 ||
529 dealt_special_dam.type_damage( DT_STAB ) > 0 ||
530 ( cur_weapon.is_null() && ( dealt_dam.type_damage( DT_CUT ) > 0 ||
531 dealt_dam.type_damage( DT_STAB ) > 0 ) ) ) {
532 if( has_trait( trait_POISONOUS ) ) {
533 add_msg_if_player( m_good, _( "You poison %s!" ), t.disp_name() );
534 t.add_effect( effect_poison, 6_turns );
535 } else if( has_trait( trait_POISONOUS2 ) ) {
536 add_msg_if_player( m_good, _( "You inject your venom into %s!" ),
537 t.disp_name() );
538 t.add_effect( effect_badpoison, 6_turns );
539 }
540 }
541
542 // Make a rather quiet sound, to alert any nearby monsters
543 if( !is_quiet() ) { // check martial arts silence
544 //sound generated later
545 sounds::sound( pos(), 8, sounds::sound_t::combat, "whack!" );
546 }
547 std::string material = "flesh";
548 if( t.is_monster() ) {
549 const monster *m = dynamic_cast<const monster *>( &t );
550 if( m->made_of( material_id( "steel" ) ) ) {
551 material = "steel";
552 }
553 }
554 sfx::generate_melee_sound( pos(), t.pos(), true, t.is_monster(), material );
555 int dam = dealt_dam.total_damage();
557
558 // Practice melee and relevant weapon skill (if any) except when using CQB bionic
559 if( !has_active_bionic( bio_cqb ) ) {
560 melee_train( *this, 5, 10, cur_weapon );
561 }
562
563 if( dam >= 5 && has_artifact_with( AEP_SAP_LIFE ) ) {
564 healall( rng( dam / 10, dam / 5 ) );
565 }
566
567 // Treat monster as seen if we see it before or after the attack
568 if( seen || g->u.sees( t ) ) {
569 std::string message = melee_message( technique, *this, dealt_dam );
570 player_hit_message( this, message, t, dam, critical_hit );
571 } else {
572 add_msg_player_or_npc( m_good, _( "You hit something." ),
573 _( "<npcname> hits something." ) );
574 }
575
576 if( !specialmsg.empty() ) {
577 add_msg_if_player( m_neutral, specialmsg );
578 }
579
580 if( critical_hit ) {
581 // trigger martial arts on-crit effects
582 martial_arts_data->ma_oncrit_effects( *this );
583 }
584
585 }
586
588 did_hit( t );
589
590 if( t.is_dead_state() ) {
591 // trigger martial arts on-kill effects
592 martial_arts_data->ma_onkill_effects( *this );
593 }
594 }
595
596 const int melee = get_skill_level( skill_melee );
597
598 // Previously calculated as 2_gram * std::max( 1, str_cur )
599 // using 16_gram normalizes it to 8 str. Same effort expenditure
600 // for each strike, regardless of weight. This is compensated
601 // for by the additional move cost as weapon weight increases
602 const int weight_cost = cur_weapon.weight() / ( 16_gram );
603 const int encumbrance_cost = roll_remainder( ( encumb( bp_arm_l ) + encumb( bp_arm_r ) ) *
604 2.0f );
605 const int deft_bonus = hit_spread < 0 && has_trait( trait_DEFT ) ? 50 : 0;
606 /** @EFFECT_MELEE reduces stamina cost of melee attacks */
607 const int mod_sta = ( weight_cost + encumbrance_cost - melee - deft_bonus + 50 ) * -1;
608 mod_stamina( std::min( -50, mod_sta ) );
609 add_msg( m_debug, "Stamina burn: %d", std::min( -50, mod_sta ) );
611 // trigger martial arts on-attack effects
612 martial_arts_data->ma_onattack_effects( *this );
613 // some things (shattering weapons) can harm the attacking creature.
615 if( t.as_character() ) {
617 t.as_character()->on_hit( this, bodypart_id( "num_bp" ), 0.0f, &dp );
618 }
619 return;
620}
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2194
void on_hit(Creature *source, bodypart_id, float, dealt_projectile_attack const *) override
This creature just got hit by an attack - possibly special/ranged attack - from source.
Definition: character.cpp:8411
bool can_miss_recovery(const item &weap) const
Returns true if the player is able to use a miss recovery technique.
std::string melee_special_effects(Creature &t, damage_instance &d, item &weap)
Handles combat effects, returns a string of any valid combat effect messages.
Definition: melee.cpp:1793
void perform_special_attacks(Creature &t, dealt_damage_instance &dealt_dam)
Performs special attacks and their effects (poisonous, stinger, etc.)
Definition: melee.cpp:1766
float hit_roll() const override
Returns the player's basic hit roll that is compared to the target's dodge roll.
Definition: melee.cpp:297
bool scored_crit(float target_dodge, const item &weap) const
Returns true if the player scores a critical hit.
Definition: melee.cpp:728
bool reach_attacking
Definition: character.h:601
void did_hit(Creature &target)
Definition: character.cpp:8406
void perform_technique(const ma_technique &technique, Creature &t, damage_instance &di, int &move_cost)
Definition: melee.cpp:1366
std::string get_miss_reason()
Returns an explanation for why the player would miss a melee attack.
Definition: melee.cpp:329
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:351
bool is_quiet() const
Returns true if the player has quiet melee attacks.
virtual bool is_monster() const
Definition: creature.h:101
virtual Character * as_character()
Definition: creature.h:116
virtual int deal_melee_attack(Creature *source, int hitroll)
Definition: creature.cpp:502
virtual float dodge_roll()=0
virtual void deal_melee_hit(Creature *source, int hit_spread, bool critical_hit, const damage_instance &dam, dealt_damage_instance &dealt_dam)
Definition: creature.cpp:521
int reach_range(const Character &guy) const
Max range of melee attack this weapon can be used for.
Definition: item.cpp:5148
matec_id id
Definition: martialarts.h:70
std::string avatar_message
Definition: martialarts.h:85
bool made_of(const material_id &m) const override
Definition: monster.cpp:958
@ AEP_SAP_LIFE
Definition: enums.h:119
void player_hit_message(Character *attacker, const std::string &message, Creature &t, int dam, bool crit=false)
Definition: melee.cpp:2132
static const efftype_id effect_badpoison("badpoison")
std::string melee_message(const ma_technique &tec, Character &p, const dealt_damage_instance &ddi)
Definition: melee.cpp:2014
static const efftype_id effect_hit_by_player("hit_by_player")
int stumble(Character &u, const item &weap)
Definition: melee.cpp:712
static const trait_id trait_POISONOUS("POISONOUS")
static void melee_train(Character &p, int lo, int hi, const item &weap)
Definition: melee.cpp:359
static const trait_id trait_DEFT("DEFT")
static const efftype_id effect_poison("poison")
static const trait_id trait_POISONOUS2("POISONOUS2")
void smash_specific(monster *z, Creature *target)
Definition: monattack.cpp:1100
void generate_melee_sound(const tripoint &source, const tripoint &target, bool hit, bool targ_mon=false, const std::string &material="flesh")
Definition: sounds.cpp:1607
int actual_crit_count
Definition: melee.h:13

References _, melee_statistic_data::actual_crit_count, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), AEP_SAP_LIFE, Creature::as_character(), item::attack_cost(), attack_cost(), melee_statistic_data::attack_count, ma_technique::avatar_message, bio_cqb, bp_arm_l, bp_arm_r, can_miss_recovery(), Creature::check_dead_state(), sounds::combat, melee_statistic_data::damage_amount, Creature::deal_melee_attack(), Creature::deal_melee_hit(), did_hit(), Creature::disp_name(), Creature::dodge_roll(), DT_CUT, DT_STAB, effect_badpoison, effect_hit_by_player, effect_poison, encumb(), g, sfx::generate_melee_sound(), get_miss_reason(), get_skill_level(), get_working_arm_count(), has_active_bionic(), has_artifact_with(), item::has_flag(), has_trait(), healall(), melee_statistic_data::hit_count, hit_roll(), ma_technique::id, Creature::is_dead_state(), Creature::is_monster(), is_mounted(), item::is_null(), Creature::is_player(), is_quiet(), m_bad, m_debug, m_good, m_info, m_neutral, monster::made_of(), martial_arts_data, melee_message(), melee_special_effects(), melee::melee_stats, melee_train(), mapgen_defer::message, MF_RIDEABLE_MECH, Creature::mod_moves(), mod_stamina(), mounted_creature, move_cost(), damage_instance::mult_damage(), name, string_id< T >::obj(), on_hit(), one_in(), perform_special_attacks(), perform_technique(), pick_technique(), player_hit_message(), Creature::pos(), pos(), reach_attacking, item::reach_range(), rng(), roll_all_damage(), roll_remainder(), scored_crit(), skill_melee, mattack::smash_specific(), sounds::sound(), string_id< T >::str(), stumble(), tec_none, dealt_damage_instance::total_damage(), trait_DEFT, trait_POISONOUS, trait_POISONOUS2, dealt_damage_instance::type_damage(), used_weapon(), weapon, and item::weight().

Referenced by block_hit(), npc::execute_action(), melee_attack(), monexamine::mfriend_menu(), avatar_action::move(), npc::move_to(), game::npc_menu(), player::on_dodge(), perform_technique(), monexamine::pet_menu(), and player::reach_attack().

◆ melee_special_effects()

std::string Character::melee_special_effects ( Creature t,
damage_instance d,
item weap 
)

Handles combat effects, returns a string of any valid combat effect messages.

Strength increases chance of breaking glass weapons (NEGATIVE)

Definition at line 1793 of file melee.cpp.

1794{
1795 std::string dump;
1796
1797 std::string target = t.disp_name();
1798
1799 if( has_active_bionic( bionic_id( "bio_shock" ) ) && get_power_level() >= 2_kJ &&
1800 ( !is_armed() || weapon.conductive() ) ) {
1801 mod_power_level( -2_kJ );
1802 d.add_damage( DT_ELECTRIC, rng( 2, 10 ) );
1803
1804 if( is_player() ) {
1805 dump += string_format( _( "You shock %s." ), target ) + "\n";
1806 } else {
1807 add_msg_if_npc( _( "<npcname> shocks %s." ), target );
1808 }
1809 }
1810
1811 if( has_active_bionic( bionic_id( "bio_heat_absorb" ) ) && !is_armed() && t.is_warm() ) {
1812 mod_power_level( 3_kJ );
1813 d.add_damage( DT_COLD, 3 );
1814 if( is_player() ) {
1815 dump += string_format( _( "You drain %s's body heat." ), target ) + "\n";
1816 } else {
1817 add_msg_if_npc( _( "<npcname> drains %s's body heat!" ), target );
1818 }
1819 }
1820
1821 if( weapon.has_flag( "FLAMING" ) ) {
1822 d.add_damage( DT_HEAT, rng( 1, 8 ) );
1823
1824 if( is_player() ) {
1825 dump += string_format( _( "You burn %s." ), target ) + "\n";
1826 } else {
1827 add_msg_player_or_npc( _( "<npcname> burns %s." ), target );
1828 }
1829 }
1830
1831 //Hurting the wielder from poorly-chosen weapons
1832 if( weap.has_flag( "HURT_WHEN_WIELDED" ) && x_in_y( 2, 3 ) ) {
1833 add_msg_if_player( m_bad, _( "The %s cuts your hand!" ), weap.tname() );
1834 deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance::physical( 0,
1835 weap.damage_melee( DT_CUT ), 0 ) );
1836 if( weap.is_two_handed( *this ) ) { // Hurt left hand too, if it was big
1837 deal_damage( nullptr, bodypart_id( "hand_l" ), damage_instance::physical( 0,
1838 weap.damage_melee( DT_CUT ), 0 ) );
1839 }
1840 }
1841
1842 const int vol = weap.volume() / 250_ml;
1843 // Glass weapons shatter sometimes
1844 if( weap.made_of( material_id( "glass" ) ) &&
1845 /** @EFFECT_STR increases chance of breaking glass weapons (NEGATIVE) */
1846 rng( 0, vol + 8 ) < vol + str_cur ) {
1847 if( is_player() ) {
1848 dump += string_format( _( "Your %s shatters!" ), weap.tname() ) + "\n";
1849 } else {
1850 add_msg_player_or_npc( m_bad, _( "Your %s shatters!" ),
1851 _( "<npcname>'s %s shatters!" ),
1852 weap.tname() );
1853 }
1854
1855 sounds::sound( pos(), 16, sounds::sound_t::combat, "Crack!", true, "smash_success",
1856 "smash_glass_contents" );
1857 // Dump its contents on the ground
1858 weap.contents.spill_contents( pos() );
1859 // Take damage
1860 deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance::physical( 0, rng( 0, vol * 2 ),
1861 0 ) );
1862 if( weap.is_two_handed( *this ) ) { // Hurt left arm too, if it was big
1863 //redeclare shatter_dam because deal_damage mutates it
1864 deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance::physical( 0, rng( 0, vol * 2 ),
1865 0 ) );
1866 }
1867 d.add_damage( DT_CUT, rng( 0, 5 + static_cast<int>( vol * 1.5 ) ) ); // Hurt the monster extra
1868 remove_weapon();
1869 }
1870
1871 if( !t.is_hallucination() ) {
1872 handle_melee_wear( weap );
1873 }
1874
1875 // on-hit effects for martial arts
1876 martial_arts_data->ma_onhit_effects( *this );
1877
1878 return dump;
1879}
item remove_weapon()
Definition: character.cpp:2571
virtual bool is_warm() const
Definition: creature.cpp:960
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5085

References _, damage_instance::add_damage(), Creature::add_msg_if_npc(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), bionic_id, sounds::combat, item::conductive(), item::contents, item::damage_melee(), deal_damage(), Creature::disp_name(), DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, get_power_level(), handle_melee_wear(), has_active_bionic(), item::has_flag(), is_armed(), Creature::is_hallucination(), Creature::is_player(), item::is_two_handed(), Creature::is_warm(), m_bad, item::made_of(), martial_arts_data, mod_power_level(), damage_instance::physical(), pos(), remove_weapon(), rng(), sounds::sound(), item_contents::spill_contents(), str_cur, string_format(), item::tname(), item::volume(), weapon, and x_in_y().

Referenced by melee_attack().

◆ mend()

void Character::mend ( int  rate_multiplier)

Handles the chance for broken limbs to spontaneously heal to 1 HP.

Definition at line 1603 of file suffer.cpp.

1604{
1605 // Wearing splints can slowly mend a broken limb back to 1 hp.
1606 bool any_broken = false;
1607 for( const bodypart_id &bp : get_all_body_parts() ) {
1608 if( is_limb_broken( bp ) ) {
1609 any_broken = true;
1610 break;
1611 }
1612 }
1613
1614 if( !any_broken ) {
1615 return;
1616 }
1617
1618 double healing_factor = 1.0;
1619 // Studies have shown that alcohol and tobacco use delay fracture healing time
1620 // Being under effect is 50% slowdown
1621 // Being addicted but not under effect scales from 25% slowdown to 75% slowdown
1622 // The improvement from being intoxicated over withdrawal is intended
1623 if( has_effect( effect_cig ) ) {
1624 healing_factor *= 0.5;
1625 } else {
1626 healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::CIG ) );
1627 }
1628
1629 if( has_effect( effect_drunk ) ) {
1630 healing_factor *= 0.5;
1631 } else {
1632 healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::ALCOHOL ) );
1633 }
1634
1635 if( get_rad() > 0 && !has_trait( trait_RADIOGENIC ) ) {
1636 healing_factor *= clamp( ( 1000.0f - get_rad() ) / 1000.0f, 0.0f, 1.0f );
1637 }
1638
1639 // Bed rest speeds up mending
1640 if( has_effect( effect_sleep ) ) {
1641 healing_factor *= 4.0;
1642 } else if( get_fatigue() > fatigue_levels::dead_tired ) {
1643 // but being dead tired does not...
1644 healing_factor *= 0.75;
1645 } else {
1646 // If not dead tired, resting without sleep also helps
1647 healing_factor *= 1.0f + rest_quality();
1648 }
1649
1650 // Being healthy helps.
1651 healing_factor *= 1.0f + get_healthy() / 200.0f;
1652
1653 // Very hungry starts lowering the chance
1654 // square rooting the value makes the numbers drop off faster when below 1
1655 healing_factor *= std::sqrt( static_cast<float>( get_stored_kcal() ) / static_cast<float>
1656 ( max_stored_kcal() ) );
1657 // Similar for thirst - starts at very thirsty, drops to 0 at parched
1658 healing_factor *= 1.0f - clamp( 1.0f * ( get_thirst() - thirst_levels::very_thirsty ) /
1659 +thirst_levels::parched, 0.0f, 1.0f );
1660
1661 // Mutagenic healing factor!
1662 bool needs_splint = true;
1663
1664 healing_factor *= mutation_value( "mending_modifier" );
1665
1666 if( has_trait( trait_REGEN_LIZ ) ) {
1667 needs_splint = false;
1668 }
1669
1670 add_msg( m_debug, "Limb mend healing factor: %.2f", healing_factor );
1671 if( healing_factor <= 0.0f ) {
1672 // The section below assumes positive healing rate
1673 return;
1674 }
1675
1676 for( const bodypart_id &bp : get_all_body_parts() ) {
1677 const bool broken = is_limb_broken( bp );
1678 if( !broken ) {
1679 continue;
1680 }
1681
1682 if( needs_splint && !worn_with_flag( "SPLINT", bp ) ) {
1683 continue;
1684 }
1685
1686 const time_duration dur_inc = 1_turns * roll_remainder( rate_multiplier * healing_factor );
1687 auto &eff = get_effect( effect_mending, bp->token );
1688 if( eff.is_null() ) {
1689 add_effect( effect_mending, dur_inc, bp->token );
1690 continue;
1691 }
1692
1693 eff.set_duration( eff.get_duration() + dur_inc );
1694
1695 if( eff.get_duration() >= eff.get_max_duration() ) {
1696 set_part_hp_cur( bp, 1 );
1697 remove_effect( effect_mending, bp->token );
1698 g->events().send<event_type::broken_bone_mends>( getID(), bp->token );
1699 //~ %s is bodypart
1700 add_msg_if_player( m_good, _( "Your %s has started to mend!" ),
1701 body_part_name( bp ) );
1702 }
1703 }
1704}
float rest_quality() const
Returns >0 if character is sitting/lying and relatively inactive.
Definition: character.cpp:6571
int addiction_level(add_type type) const
Returns the intensity of the specified addiction.
Definition: suffer.cpp:1959
@ broken
Definition: enums.h:323
static const efftype_id effect_drunk("drunk")
static const trait_id trait_REGEN_LIZ("REGEN_LIZ")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static float addiction_scaling(float at_min, float at_max, float add_lvl)
Definition: suffer.cpp:172
static const efftype_id effect_mending("mending")
static const trait_id trait_RADIOGENIC("RADIOGENIC")

References _, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), addiction_level(), addiction_scaling(), ALCOHOL, body_part_name(), broken, broken_bone_mends, CIG, clamp(), dead_tired, effect_cig, effect_drunk, effect_mending, effect_sleep, g, Creature::get_all_body_parts(), Creature::get_effect(), get_fatigue(), get_healthy(), get_rad(), get_stored_kcal(), get_thirst(), getID(), Creature::has_effect(), has_trait(), is_limb_broken(), m_debug, m_good, max_stored_kcal(), mutation_value(), parched, Creature::remove_effect(), rest_quality(), roll_remainder(), Creature::set_part_hp_cur(), trait_RADIOGENIC, trait_REGEN_LIZ, very_thirsty, and worn_with_flag().

Referenced by update_body().

◆ metabolic_rate()

float Character::metabolic_rate ( ) const

Current metabolic rate due to traits, hunger, speed, etc.

Definition at line 610 of file consumption.cpp.

611{
612 return metabolic_rate_base();
613}

References metabolic_rate_base().

Referenced by calc_needs_rates().

◆ metabolic_rate_base()

float Character::metabolic_rate_base ( ) const

Stable base metabolic rate due to traits.

Definition at line 597 of file consumption.cpp.

598{
599 static const std::string hunger_rate_string( "PLAYER_HUNGER_RATE" );
600 static const std::string metabolism_modifier( "metabolism_modifier" );
601
602 float hunger_rate = get_option< float >( hunger_rate_string );
603 float mut_bonus = 1.0f + mutation_value( metabolism_modifier );
604 float with_mut = hunger_rate * mut_bonus;
605 float ench_bonus = bonus_from_enchantments( with_mut, enchant_vals::mod::METABOLISM );
606
607 return std::max( 0.0f, with_mut + ench_bonus );
608}

References bonus_from_enchantments(), enchant_vals::METABOLISM, and mutation_value().

Referenced by bmr(), and metabolic_rate().

◆ mod_base_age()

void Character::mod_base_age ( int  mod)

Definition at line 6910 of file character.cpp.

6911{
6912 init_age += mod;
6913}

References init_age.

Referenced by set_description().

◆ mod_base_height()

void Character::mod_base_height ( int  mod)

Definition at line 6939 of file character.cpp.

6940{
6941 init_height += mod;
6942}

References init_height.

Referenced by set_description().

◆ mod_dex_bonus()

void Character::mod_dex_bonus ( int  ndex)
virtual

◆ mod_fatigue()

◆ mod_healthy()

void Character::mod_healthy ( int  nhealthy)
virtual

Modifiers for health values exclusive to characters.

Definition at line 4262 of file character.cpp.

4263{
4264 float mut_rate = 1.0f;
4265 for( const trait_id &mut : get_mutations() ) {
4266 mut_rate *= mut.obj().healthy_rate;
4267 }
4268 healthy += nhealthy * mut_rate;
4269}

References get_mutations(), and healthy.

Referenced by iuse::adrenaline_injector(), mod_stat(), player::process_one_effect(), spell_effect::recover_energy(), and update_health().

◆ mod_healthy_mod()

void Character::mod_healthy_mod ( int  nhealthy_mod,
int  cap 
)
virtual

Definition at line 4274 of file character.cpp.

4275{
4276 // TODO: This really should be a full morale-like system, with per-effect caps
4277 // and durations. This version prevents any single effect from exceeding its
4278 // intended ceiling, but multiple effects will overlap instead of adding.
4279
4280 // Cap indicates how far the mod is allowed to shift in this direction.
4281 // It can have a different sign to the mod, e.g. for items that treat
4282 // extremely low health, but can't make you healthy.
4283 if( nhealthy_mod == 0 || cap == 0 ) {
4284 return;
4285 }
4286 int low_cap;
4287 int high_cap;
4288 if( nhealthy_mod < 0 ) {
4289 low_cap = cap;
4290 high_cap = 200;
4291 } else {
4292 low_cap = -200;
4293 high_cap = cap;
4294 }
4295
4296 // If we're already out-of-bounds, we don't need to do anything.
4297 if( ( healthy_mod <= low_cap && nhealthy_mod < 0 ) ||
4298 ( healthy_mod >= high_cap && nhealthy_mod > 0 ) ) {
4299 return;
4300 }
4301
4302 healthy_mod += nhealthy_mod;
4303
4304 // Since we already bailed out if we were out-of-bounds, we can
4305 // just clamp to the boundaries here.
4306 healthy_mod = std::min( healthy_mod, high_cap );
4307 healthy_mod = std::max( healthy_mod, low_cap );
4308}

References healthy_mod.

Referenced by addict_effect(), iuse::blech(), check_needs_extremes(), consume_effects(), player::hardcoded_effects(), modify_health(), iuse::mycus(), iuse::plantblech(), player::process_one_effect(), rooted(), suffer_from_bad_bionics(), suffer_from_other_mutations(), update_health(), and iuse::vaccine().

◆ mod_int_bonus()

void Character::mod_int_bonus ( int  nint)
virtual

◆ mod_max_power_level()

void Character::mod_max_power_level ( const units::energy npower_max)

Definition at line 2002 of file character.cpp.

2003{
2004 max_power_level += npower_max;
2005}

References max_power_level.

Referenced by activate_mutation(), add_bionic(), perform_uninstall(), and uninstall_bionic().

◆ mod_painkiller()

void Character::mod_painkiller ( int  npkill)

◆ mod_per_bonus()

void Character::mod_per_bonus ( int  nper)
virtual

◆ mod_power_level()

void Character::mod_power_level ( const units::energy npower)

Definition at line 1990 of file character.cpp.

1991{
1992 // Remaining capacity between current and maximum power levels we can make use of.
1993 const units::energy remaining_capacity = get_max_power_level() - get_power_level();
1994 // We can't add more than remaining capacity, so get the minimum of the two
1995 const units::energy minned_npower = std::min( npower, remaining_capacity );
1996 // new candidate power level
1997 const units::energy new_power = get_power_level() + minned_npower;
1998 // set new power level while prevending it from going negative
1999 set_power_level( std::max( 0_kJ, new_power ) );
2000}

References get_max_power_level(), get_power_level(), and set_power_level().

Referenced by activate_bionic(), activate_mutation(), burn_fuel(), npc::check_or_use_weapon_cbm(), deactivate_bionic(), npc::discharge_cbm_weapon(), do_skill_rust(), player::eat(), iuse::ehandcuffs(), explosion_handler::emp_blast(), feed_furnace_with(), aim_activity_actor::finish(), iexamine::fireplace(), hack_attempt(), melee_special_effects(), game::monmove(), player::on_hit(), game::on_move_effects(), passive_power_gen(), game::phasing_move(), process_bionic(), player::process_turn(), npc::recharge_cbm(), spell_effect::recover_energy(), mattack::riotbot(), activity_handlers::spellcasting_finish(), suffer_from_asthma(), suffer_from_bad_bionics(), suffer_from_radiation(), suffer_while_underwater(), try_start_hacking(), player::uncanny_dodge(), update_stamina(), use_charges(), and use_fire().

◆ mod_rad()

void Character::mod_rad ( int  mod)

Definition at line 7200 of file character.cpp.

7201{
7202 if( has_trait_flag( "NO_RADIATION" ) ) {
7203 return;
7204 }
7205 set_rad( std::max( 0, get_rad() + mod ) );
7206}

References get_rad(), has_trait_flag(), and set_rad().

Referenced by activate_bionic(), irradiate(), game::process_artifact(), player::process_one_effect(), regen(), and suffer_from_radiation().

◆ mod_skill_level()

void Character::mod_skill_level ( const skill_id ident,
int  delta 
)

Definition at line 3374 of file character.cpp.

3375{
3376 _skills->mod_skill_level( ident, delta );
3377}

References _skills.

Referenced by avatar::create(), npc::randomize(), and set_skills().

◆ mod_sleep_deprivation()

void Character::mod_sleep_deprivation ( int  nsleep_deprivation)
virtual

Definition at line 4451 of file character.cpp.

4452{
4453 set_sleep_deprivation( sleep_deprivation + nsleep_deprivation );
4454}
virtual void set_sleep_deprivation(int nsleep_deprivation)
Definition: character.cpp:4465

References set_sleep_deprivation(), and sleep_deprivation.

Referenced by update_needs().

◆ mod_stamina()

◆ mod_stat()

void Character::mod_stat ( const std::string &  stat,
float  modifier 
)
overridevirtual

Reimplemented from Creature.

Reimplemented in player.

Definition at line 520 of file character.cpp.

521{
522 if( stat == "str" ) {
523 mod_str_bonus( modifier );
524 } else if( stat == "dex" ) {
525 mod_dex_bonus( modifier );
526 } else if( stat == "per" ) {
527 mod_per_bonus( modifier );
528 } else if( stat == "int" ) {
529 mod_int_bonus( modifier );
530 } else if( stat == "healthy" ) {
531 mod_healthy( modifier );
532 } else if( stat == "kcal" ) {
533 mod_stored_kcal( modifier );
534 } else if( stat == "hunger" ) {
535 mod_stored_kcal( -10 * modifier );
536 } else {
537 Creature::mod_stat( stat, modifier );
538 }
539}
virtual void mod_healthy(int nhealthy)
Modifiers for health values exclusive to characters.
Definition: character.cpp:4262
virtual void mod_per_bonus(int nper)
Definition: character.cpp:4200
virtual void mod_dex_bonus(int ndex)
Definition: character.cpp:4195
virtual void mod_str_bonus(int nstr)
Definition: character.cpp:4190
virtual void mod_int_bonus(int nint)
Definition: character.cpp:4205
virtual void mod_stat(const std::string &stat, float modifier)
Definition: creature.cpp:1695

References mod_dex_bonus(), mod_healthy(), mod_int_bonus(), mod_per_bonus(), Creature::mod_stat(), mod_stored_kcal(), and mod_str_bonus().

Referenced by apply_skill_boost(), player::mod_stat(), and shout().

◆ mod_stim()

◆ mod_stored_kcal()

◆ mod_stored_nutr()

◆ mod_str_bonus()

◆ mod_thirst()

◆ modify_addiction()

void Character::modify_addiction ( const islot_comestible comest)

Used to apply addiction modifications from food and medication.

Definition at line 1052 of file consumption.cpp.

1053{
1054 add_addiction( comest.add, comest.addict );
1055 if( addiction_craving( comest.add ) != MORALE_NULL ) {
1056 rem_morale( addiction_craving( comest.add ) );
1057 }
1058}
morale_type addiction_craving(add_type const cur)
Definition: addiction.cpp:307
void add_addiction(add_type type, int strength)
Adds an addiction to the player.
Definition: suffer.cpp:1890
add_type add
effects of addiction
Definition: itype.h:142
int addict
addiction potential
Definition: itype.h:139

References islot_comestible::add, add_addiction(), islot_comestible::addict, addiction_craving(), MORALE_NULL, and rem_morale().

Referenced by consume_effects(), and player::consume_med().

◆ modify_fatigue()

void Character::modify_fatigue ( const islot_comestible comest)

Used to apply fatigue modifications from food and medication.

Definition at line 1042 of file consumption.cpp.

1043{
1044 mod_fatigue( -comest.fatigue_mod );
1045}
int fatigue_mod
fatigue altering effect
Definition: itype.h:148

References islot_comestible::fatigue_mod, and mod_fatigue().

Referenced by consume_effects(), and player::consume_med().

◆ modify_health()

void Character::modify_health ( const islot_comestible comest)

Used to apply health modifications from food and medication.

Definition at line 999 of file consumption.cpp.

1000{
1001 const int effective_health = comest.healthy;
1002 // Effectively no cap on health modifiers from food and meds
1003 const int health_cap = 200;
1004 mod_healthy_mod( effective_health, effective_health >= 0 ? health_cap : -health_cap );
1005}
int healthy
TODO: add documentation.
Definition: itype.h:157

References islot_comestible::healthy, and mod_healthy_mod().

Referenced by consume_effects(), and player::consume_med().

◆ modify_morale()

void Character::modify_morale ( item food,
int  nutr = 0 
)

Used to apply morale modifications from food and medication.

Definition at line 1060 of file consumption.cpp.

1061{
1062 time_duration morale_time = 2_hours;
1063 if( food.has_flag( flag_EATEN_HOT ) ) {
1064 auto heater = find_food_heater( *this, crafting_inventory(),
1065 get_map().has_nearby_fire( pos(), PICKUP_RANGE ) );
1066 if( heater && heater->consume( *this ) ) {
1068 _( "You heat up your %1$s using the %2$s." ),
1069 _( "<npcname> heats up their %1$s using the %2$s." ),
1070 food.tname(), heater->it.tname() );
1071 morale_time = 3_hours;
1072 int clamped_nutr = std::max( 5, std::min( 20, nutr / 10 ) );
1073 add_morale( MORALE_FOOD_HOT, clamped_nutr, 20, morale_time, morale_time / 2 );
1074 }
1075 }
1076
1077 std::pair<int, int> fun = fun_for( food );
1078 if( fun.first < 0 ) {
1079 add_morale( MORALE_FOOD_BAD, fun.first, fun.second, morale_time, morale_time / 2, false,
1080 food.type );
1081 } else if( fun.first > 0 ) {
1082 add_morale( MORALE_FOOD_GOOD, fun.first, fun.second, morale_time, morale_time / 2, false,
1083 food.type );
1084 }
1085
1086 if( food.has_flag( flag_HIDDEN_HALLU ) ) {
1087 if( has_trait( trait_SPIRITUAL ) ) {
1088 add_morale( MORALE_FOOD_GOOD, 36, 72, 2_hours, 1_hours, false );
1089 } else {
1090 add_morale( MORALE_FOOD_GOOD, 18, 36, 1_hours, 30_minutes, false );
1091 }
1092 }
1093
1094 if( food.has_flag( flag_CANNIBALISM ) ) {
1095 const bool cannibal = has_trait( trait_CANNIBAL );
1096 const bool psycho = has_trait( trait_PSYCHOPATH );
1097 const bool sapiovore = has_trait( trait_SAPIOVORE );
1098 if( cannibal ) {
1099 add_msg_if_player( m_good, _( "You indulge your shameful hunger." ) );
1100 add_morale( MORALE_CANNIBAL, 20, 200 );
1101 } else if( psycho || sapiovore ) {
1102 // Nothing - doesn't care enough to print a message
1103 } else {
1104 add_msg_if_player( m_bad, _( "You feel horrible for eating a person." ) );
1105 add_morale( MORALE_CANNIBAL, -60, -400, 60_minutes, 30_minutes );
1106 }
1107 }
1108
1109 // Allergy check for food that is ingested (not gum)
1110 if( !food.has_flag( "NO_INGEST" ) ) {
1111 const auto allergy = allergy_type( food );
1112 if( allergy != MORALE_NULL ) {
1113 add_msg_if_player( m_bad, _( "Yuck! How can anybody eat this stuff?" ) );
1114 add_morale( allergy, -75, -400, 30_minutes, 24_minutes );
1115 }
1116 if( food.has_flag( flag_ALLERGEN_JUNK ) ) {
1117 if( has_trait( trait_PROJUNK ) ) {
1118 add_msg_if_player( m_good, _( "Mmm, junk food." ) );
1119 add_morale( MORALE_SWEETTOOTH, 5, 30, 30_minutes, 24_minutes );
1120 }
1121 if( has_trait( trait_PROJUNK2 ) ) {
1122 if( !one_in( 100 ) ) {
1123 add_msg_if_player( m_good, _( "When life's got you down, there's always sugar." ) );
1124 } else {
1125 add_msg_if_player( m_good, _( "They may do what they must… you've already won." ) );
1126 }
1127 add_morale( MORALE_SWEETTOOTH, 10, 50, 1_hours, 50_minutes );
1128 }
1129 // Carnivores CAN eat junk food, but they won't like it much.
1130 // Pizza-scraping happens in consume_effects.
1132 add_msg_if_player( m_bad, _( "Your stomach begins gurgling and you feel bloated and ill." ) );
1133 add_morale( MORALE_NO_DIGEST, -25, -125, 30_minutes, 24_minutes );
1134 }
1135 }
1136 }
1137 const bool chew = food.get_comestible()->comesttype == comesttype_FOOD ||
1139 if( !food.rotten() && chew && has_trait( trait_SAPROPHAGE ) ) {
1140 // It's OK to *drink* things that haven't rotted. Alternative is to ban water. D:
1141 add_msg_if_player( m_bad, _( "Your stomach begins gurgling and you feel bloated and ill." ) );
1142 add_morale( MORALE_NO_DIGEST, -75, -400, 30_minutes, 24_minutes );
1143 }
1144 if( food.has_flag( flag_URSINE_HONEY ) && ( !crossed_threshold() ||
1146 mutation_category_level["URSINE"] > 40 ) {
1147 // Need at least 5 bear mutations for effect to show, to filter out mutations in common with other categories
1148 int honey_fun = has_trait( trait_THRESH_URSINE ) ?
1149 std::min( mutation_category_level["URSINE"] / 8, 20 ) :
1150 mutation_category_level["URSINE"] / 12;
1151 if( honey_fun < 10 ) {
1152 add_msg_if_player( m_good, _( "You find the sweet taste of honey surprisingly palatable." ) );
1153 } else {
1154 add_msg_if_player( m_good, _( "You feast upon the sweet honey." ) );
1155 }
1156 add_morale( MORALE_HONEY, honey_fun, 100 );
1157 }
1158}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
bool crossed_threshold() const
Returns true if the player has crossed a mutation threshold Player can only cross one mutation thresh...
Definition: character.cpp:8730
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:853
static cata::optional< prepared_item_consumption > find_food_heater(Character &c, const inventory &inv, bool has_fire)
static const trait_id trait_THRESH_URSINE("THRESH_URSINE")
static const std::string flag_URSINE_HONEY("URSINE_HONEY")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPIOVORE("SAPIOVORE")
static const trait_id trait_PSYCHOPATH("PSYCHOPATH")
static const trait_id trait_PROJUNK("PROJUNK")
static const trait_id trait_SPIRITUAL("SPIRITUAL")
static const std::string flag_EATEN_HOT("EATEN_HOT")
static const trait_id trait_CANNIBAL("CANNIBAL")
const morale_type MORALE_HONEY("morale_honey")
const morale_type MORALE_SWEETTOOTH("morale_sweettooth")
const morale_type MORALE_NO_DIGEST("morale_no_digest")
const morale_type MORALE_FOOD_HOT("morale_food_hot")
const morale_type MORALE_FOOD_GOOD("morale_food_good")
const morale_type MORALE_CANNIBAL("morale_cannibal")
const morale_type MORALE_FOOD_BAD("morale_food_bad")
int chew(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:1101

References _, add_morale(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), allergy, allergy_type(), iuse::chew(), comesttype_FOOD(), crafting_inventory(), crossed_threshold(), find_food_heater(), flag_ALLERGEN_JUNK(), flag_CANNIBALISM(), flag_CARNIVORE_OK(), flag_EATEN_HOT(), flag_HIDDEN_HALLU(), flag_URSINE_HONEY(), flag_USE_EAT_VERB(), fun_for(), item::get_comestible(), get_map(), item::has_flag(), has_trait(), m_bad, m_good, MORALE_CANNIBAL, MORALE_FOOD_BAD, MORALE_FOOD_GOOD, MORALE_FOOD_HOT, MORALE_HONEY, MORALE_NO_DIGEST, MORALE_NULL, MORALE_SWEETTOOTH, mutation_category_level, one_in(), PICKUP_RANGE, pos(), item::rotten(), item::tname(), trait_CANNIBAL, trait_CARNIVORE, trait_PROJUNK, trait_PROJUNK2, trait_PSYCHOPATH, trait_SAPIOVORE, trait_SAPROPHAGE, trait_SPIRITUAL, trait_THRESH_URSINE, and item::type.

Referenced by consume_effects(), and player::consume_med().

◆ modify_radiation()

void Character::modify_radiation ( const islot_comestible comest)

Used to apply radiation from food and medication.

Definition at line 1047 of file consumption.cpp.

1048{
1049 irradiate( comest.radiation );
1050}
bool irradiate(float rads, bool bypass=false)
Handles mitigation and application of radiation.
Definition: suffer.cpp:1532
int radiation
Amount of radiation you get from this comestible.
Definition: itype.h:163

References irradiate(), and islot_comestible::radiation.

Referenced by consume_effects(), and player::consume_med().

◆ modify_stimulation()

void Character::modify_stimulation ( const islot_comestible comest)

Used to apply stimulation modifications from food and medication.

Definition at line 1007 of file consumption.cpp.

1008{
1009 const int current_stim = get_stim();
1010 if( comest.stim != 0 &&
1011 ( std::abs( current_stim ) < ( std::abs( comest.stim ) * 3 ) ||
1012 sgn( current_stim ) != sgn( comest.stim ) ) ) {
1013 if( comest.stim < 0 ) {
1014 set_stim( std::max( comest.stim * 3, current_stim + comest.stim ) );
1015 } else {
1016 set_stim( std::min( comest.stim * 3, current_stim + comest.stim ) );
1017 }
1018 }
1019 if( has_trait( trait_STIMBOOST ) && ( current_stim > 30 ) &&
1020 ( ( comest.add == add_type::CAFFEINE ) || ( comest.add == add_type::SPEED ) ||
1021 ( comest.add == add_type::COKE ) || ( comest.add == add_type::CRACK ) ) ) {
1022 int hallu_duration = ( current_stim - comest.stim < 30 ) ? current_stim - 30 : comest.stim;
1023 add_effect( effect_visuals, hallu_duration * 30_minutes );
1024 std::vector<std::string> stimboost_msg{ _( "The shadows are getting ever closer." ),
1025 _( "You have a bad feeling about this." ),
1026 _( "A powerful sense of dread comes over you." ),
1027 _( "Your skin starts crawling." ),
1028 _( "They're coming to get you." ),
1029 _( "This might've been a bad idea…" ),
1030 _( "You've really done it this time, haven't you?" ),
1031 _( "You have to stay vigilant. They're always watching…" ),
1032 _( "mistake mistake mistake mistake mistake" ),
1033 _( "Just gotta stay calm, and you'll make it through this." ),
1034 _( "You're starting to feel very jumpy." ),
1035 _( "Something is twitching at the edge of your vision." ),
1036 _( "They know what you've done…" ),
1037 _( "You're feeling even more paranoid than usual." ) };
1038 add_msg_if_player( m_bad, random_entry_ref( stimboost_msg ) );
1039 }
1040}
static const efftype_id effect_visuals("visuals")
static const trait_id trait_STIMBOOST("STIMBOOST")
constexpr int sgn(const T x)
Definition: enums.h:8
std::enable_if<!is_std_array< C >::value, constV & >::type random_entry_ref(const C &container)
Same as above, but with a statically allocated default value (using the default constructor).
Definition: rng.h:149
int stim
stimulant effect
Definition: itype.h:145

References _, islot_comestible::add, Creature::add_effect(), Creature::add_msg_if_player(), CAFFEINE, COKE, CRACK, effect_visuals, get_stim(), has_trait(), m_bad, random_entry_ref(), set_stim(), sgn(), SPEED, islot_comestible::stim, and trait_STIMBOOST.

Referenced by consume_effects(), and player::consume_med().

◆ mount_creature()

void Character::mount_creature ( monster z)

Definition at line 1033 of file character.cpp.

1034{
1035 tripoint pnt = z.pos();
1036 shared_ptr_fast<monster> mons = g->shared_from( z );
1037 if( mons == nullptr ) {
1038 add_msg( m_debug, "mount_creature(): monster not found in critter_tracker" );
1039 return;
1040 }
1041 add_effect( effect_riding, 1_turns, num_bp );
1042 z.add_effect( effect_ridden, 1_turns, num_bp );
1043 if( z.has_effect( effect_tied ) ) {
1045 if( z.tied_item ) {
1046 i_add( *z.tied_item );
1047 z.tied_item.reset();
1048 }
1049 }
1051 if( z.has_effect( effect_harnessed ) ) {
1053 add_msg_if_player( m_info, _( "You remove the %s's harness." ), z.get_name() );
1054 }
1055 mounted_creature = mons;
1056 mons->mounted_player = this;
1057 if( is_avatar() ) {
1058 if( g->u.is_hauling() ) {
1059 g->u.stop_hauling();
1060 }
1061 if( g->u.get_grab_type() != OBJECT_NONE ) {
1062 add_msg( m_warning, _( "You let go of the grabbed object." ) );
1063 g->u.grab( OBJECT_NONE );
1064 }
1065 g->place_player( pnt );
1066 } else {
1067 npc &guy = dynamic_cast<npc &>( *this );
1068 guy.setpos( pnt );
1069 }
1070 z.facing = facing;
1071 add_msg_if_player( m_good, _( "You climb on the %s." ), z.get_name() );
1072 if( z.has_flag( MF_RIDEABLE_MECH ) ) {
1073 if( !z.type->mech_weapon.is_empty() ) {
1074 item mechwep = item( z.type->mech_weapon );
1075 wield( mechwep );
1076 }
1077 add_msg_if_player( m_good, _( "You hear your %s whir to life." ), z.get_name() );
1078 }
1079 // some rideable mechs have night-vision
1081 mod_moves( -100 );
1082}
static const efftype_id effect_tied("tied")
static const efftype_id effect_harnessed("harnessed")
FacingDirection facing
return the direction the creature is facing, for sdl horizontal flip
Definition: creature.h:135
cata::value_ptr< item > tied_item
Definition: monster.h:463
std::string get_name() const override
Definition: monster.cpp:487
void setpos(const tripoint &pos) override
Note: this places NPC on a given position in CURRENT MAP coordinates.
Definition: npc.cpp:681
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, Creature::add_effect(), monster::add_effect(), add_msg(), Creature::add_msg_if_player(), effect_harnessed, effect_ridden, effect_riding, effect_tied, Creature::facing, g, monster::get_name(), getID(), Creature::has_effect(), monster::has_flag(), i_add(), Creature::is_avatar(), string_id< T >::is_empty(), m_debug, m_good, m_info, m_warning, mtype::mech_weapon, MF_RIDEABLE_MECH, Creature::mod_moves(), mounted_creature, monster::mounted_player_id, num_bp, OBJECT_NONE, monster::pos(), recalc_sight_limits(), Creature::remove_effect(), npc::setpos(), monster::tied_item, monster::type, and wield().

Referenced by activity_handlers::find_mount_do_turn().

◆ move_effects()

bool Character::move_effects ( bool  attacking)
overridevirtual

Processes effects which may prevent the Character from moving (bear traps, crushed, etc.).

Returns false if movement is stopped.

Strength increases chance to escape pit Dexterity increases chance to escape pit, slightly

Implements Creature.

Definition at line 1538 of file character.cpp.

1539{
1540 if( has_effect( effect_downed ) ) {
1541 try_remove_downed( *this );
1542 return false;
1543 }
1544 if( has_effect( effect_webbed ) ) {
1545 try_remove_webs( *this );
1546 return false;
1547 }
1548 if( has_effect( effect_lightsnare ) ) {
1549 try_remove_lightsnare( *this );
1550 return false;
1551
1552 }
1553 if( has_effect( effect_heavysnare ) ) {
1554 try_remove_heavysnare( *this );
1555 return false;
1556 }
1557 if( has_effect( effect_beartrap ) ) {
1558 try_remove_bear_trap( *this );
1559 return false;
1560 }
1561 if( has_effect( effect_crushed ) ) {
1562 try_remove_crushed( *this );
1563 return false;
1564 }
1565 // Below this point are things that allow for movement if they succeed
1566
1567 // Currently we only have one thing that forces movement if you succeed, should we get more
1568 // than this will need to be reworked to only have success effects if /all/ checks succeed
1569 if( has_effect( effect_in_pit ) ) {
1570 /** @EFFECT_STR increases chance to escape pit */
1571
1572 /** @EFFECT_DEX increases chance to escape pit, slightly */
1573 if( rng( 0, 40 ) > get_str() + get_dex() / 2 ) {
1574 add_msg_if_player( m_bad, _( "You try to escape the pit, but slip back in." ) );
1575 return false;
1576 } else {
1577 add_msg_player_or_npc( m_good, _( "You escape the pit!" ),
1578 _( "<npcname> escapes the pit!" ) );
1580 }
1581 }
1582 if( has_effect( effect_grabbed ) && !attacking && !try_remove_grab( *this ) ) {
1583 // NOLINTNEXTLINE(readability-simplify-boolean-expr)
1584 return false;
1585 }
1586 return true;
1587}
static void try_remove_lightsnare(Character &c)
Definition: character.cpp:1388
static void try_remove_crushed(Character &c)
Definition: character.cpp:1448
static const efftype_id effect_crushed("crushed")
static void try_remove_heavysnare(Character &c)
Definition: character.cpp:1417
static void try_remove_bear_trap(Character &c)
Definition: character.cpp:1352
static void try_remove_webs(Character &c)
Definition: character.cpp:1518
static bool try_remove_grab(Character &c)
Definition: character.cpp:1462
static const efftype_id effect_webbed("webbed")
static const efftype_id effect_in_pit("in_pit")
static void try_remove_downed(Character &c)
Definition: character.cpp:1337

References _, Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), effect_beartrap, effect_crushed, effect_downed, effect_grabbed, effect_heavysnare, effect_in_pit, effect_lightsnare, effect_webbed, get_dex(), get_str(), Creature::has_effect(), m_bad, m_good, Creature::remove_effect(), rng(), try_remove_bear_trap(), try_remove_crushed(), try_remove_downed(), try_remove_grab(), try_remove_heavysnare(), try_remove_lightsnare(), and try_remove_webs().

Referenced by avatar_action::move(), npc::move_to(), and game::vertical_move().

◆ movement_mode_is()

bool Character::movement_mode_is ( character_movemode  mode) const

Check against the character's current movement mode.

Definition at line 1622 of file character.cpp.

1623{
1624 return move_mode == mode;
1625}

References move_mode.

Referenced by avatar::cycle_move_mode(), draw_health_classic(), avatar_action::move(), move_mode_color(), move_mode_string(), game::on_move_effects(), Creature::sees(), game::vertical_move(), and game::walk_move().

◆ mut_cbm_encumb()

void Character::mut_cbm_encumb ( char_encumbrance_data vals) const
protected

Applies encumbrance from mutations and bionics only.

Definition at line 4037 of file character.cpp.

4038{
4039
4040 for( const bionic_id &bid : get_bionics() ) {
4041 for( const std::pair<const bodypart_str_id, int> &element : bid->encumbrance ) {
4042 vals.elems[element.first->token].encumbrance += element.second;
4043 }
4044 }
4045
4047 for( auto &val : vals.elems ) {
4048 val.encumbrance += 3; // Slight encumbrance to all parts except eyes
4049 }
4050 vals.elems[bp_eyes].encumbrance -= 3;
4051 }
4052
4053 // Lower penalty for bps covered only by XL armor
4054 const auto oversize = exclusive_flag_coverage( flag_OVERSIZE );
4055 for( const trait_id &mut : get_mutations() ) {
4056 apply_mut_encumbrance( vals, mut, oversize );
4057 }
4058}
static const bionic_id bio_shock_absorber("bio_shock_absorber")
static void apply_mut_encumbrance(char_encumbrance_data &vals, const trait_id &mut, const body_part_set &oversize)
Definition: character.cpp:4022

References apply_mut_encumbrance(), bio_shock_absorber, bp_eyes, char_encumbrance_data::elems, exclusive_flag_coverage(), flag_OVERSIZE(), get_bionics(), get_mutations(), and has_active_bionic().

Referenced by calc_encumbrance().

◆ mutate()

void Character::mutate ( )

Picks a random valid mutation and gives it to the Character, possibly removing/changing others along the way.

Definition at line 845 of file mutation.cpp.

846{
847 if( get_option<bool>( "BALANCED_MUTATIONS" ) ) {
849 if( !mutagen ) {
850 return;
851 }
852 float mut_power = to_turns<float>( mutagen.get_duration() ) / to_turns<float>
853 ( mutagen.get_int_dur_factor() );
854 add_msg_if_player( m_debug, "Mutation accumulation: %.1f", mut_power );
855 while( mut_power > 1 || roll_remainder( mut_power ) > 0 ) {
856 std::map<trait_id, float> chances = mutation_chances();
857
858 weighted_float_list<trait_id> mutation_picker;
859 for( const auto &p : chances ) {
860 mutation_picker.add( p.first, p.second );
861 }
862
863 for( int tries = 0; tries < 3; tries++ ) {
864 const trait_id *selected = mutation_picker.pick();
865 if( selected == nullptr ) {
866 continue;
867 }
868 add_msg_if_player( m_debug, "Selected mutation %s", selected->obj().name().c_str() );
869 if( has_trait( *selected ) ) {
870 remove_mutation( *selected );
871 break;
872 } else {
873 mutate_towards( *selected );
874 break;
875 }
876 }
877
878 mutagen.mod_duration( -mutagen.get_int_dur_factor() );
879 mut_power -= 1.0f;
880 }
881 } else {
882 old_mutate();
884 }
885}
void remove_mutation(const trait_id &mut, bool silent=false)
Removes a mutation, downgrading to the previous level if possible.
Definition: mutation.cpp:1338
bool mutate_towards(std::vector< trait_id > muts, int num_tries=INT_MAX)
Mutates toward one of the given mutations, upgrading or removing conflicts if necessary.
Definition: mutation.cpp:1097
std::map< trait_id, float > mutation_chances() const
Calculate percentage chances for mutations.
Definition: mutation.cpp:752
void old_mutate()
Definition: mutation.cpp:887
time_duration get_int_dur_factor() const
Returns the number of turns it takes for the intensity to fall by 1 or 0 if intensity isn't based on ...
Definition: effect.cpp:1207
static const efftype_id effect_accumulated_mutagen("accumulated_mutagen")
T * add(const T &obj, const W &weight)
This will add a new object to the weighted list.
Definition: weighted_list.h:33
const T * pick(unsigned int randi) const
This will return a pointer to an object from the list randomly selected and biased by weight.
Definition: weighted_list.h:94

References weighted_list< W, T >::add(), Creature::add_msg_if_player(), effect_accumulated_mutagen, effect::get_duration(), Creature::get_effect(), effect::get_int_dur_factor(), has_trait(), m_debug, effect::mod_duration(), mutate_towards(), mutation_chances(), mutation_branch::name(), old_mutate(), weighted_list< W, T >::pick(), Creature::remove_effect(), remove_mutation(), and roll_remainder().

Referenced by iuse::artifact(), eff_fun_mutating(), player::hardcoded_effects(), marloss_common(), spell_effect::mutate(), mutate_category(), iuse::mycus(), mattack::science(), iuse::sewage(), suffer_from_artifacts(), suffer_from_other_mutations(), and suffer_from_radiation().

◆ mutate_category()

void Character::mutate_category ( const std::string &  mut_cat)

Picks a random valid mutation in a category and mutate_towards() it.

Definition at line 1044 of file mutation.cpp.

1045{
1046 // Hacky ID comparison is better than separate hardcoded branch used before
1047 // TODO: Turn it into the null id
1048 if( cat == "ANY" ) {
1049 mutate();
1050 return;
1051 }
1052
1053 bool force_bad = one_in( 3 ) && !get_option<bool>( "BALANCED_MUTATIONS" );
1054 bool force_good = false;
1055 if( has_trait( trait_ROBUST ) && force_bad ) {
1056 // Robust Genetics gives you a 33% chance for a good mutation,
1057 // instead of the 33% chance of a bad one.
1058 force_bad = false;
1059 force_good = true;
1060 }
1061 if( has_trait( trait_CHAOTIC_BAD ) ) {
1062 force_bad = true;
1063 force_good = false;
1064 }
1065
1066 // Pull the category's list for valid mutations
1067 std::vector<trait_id> valid = mutations_category[cat];
1068
1069 // Remove anything we already have, that we have a child of, or that
1070 // goes against our intention of a good/bad mutation
1071 for( size_t i = 0; i < valid.size(); i++ ) {
1072 if( !mutation_ok( valid[i], force_good, force_bad ) ) {
1073 valid.erase( valid.begin() + i );
1074 i--;
1075 }
1076 }
1077
1078 mutate_towards( valid, 2 );
1079}
void mutate()
Picks a random valid mutation and gives it to the Character, possibly removing/changing others along ...
Definition: mutation.cpp:845
bool mutation_ok(const trait_id &mutation, bool force_good, bool force_bad) const
Returns true if the player doesn't have the mutation or a conflicting one and it complies with the fo...
Definition: mutation.cpp:639
static const trait_id trait_CHAOTIC_BAD("CHAOTIC_BAD")
static const trait_id trait_ROBUST("ROBUST")
std::map< std::string, std::vector< trait_id > > mutations_category

References has_trait(), mutate(), mutate_towards(), mutation_ok(), mutations_category, one_in(), trait_CHAOTIC_BAD, and trait_ROBUST.

Referenced by eff_fun_rat(), player::hardcoded_effects(), spell_effect::mutate(), iuse::mycus(), npc::randomize(), mutagen_actor::use(), and mutagen_iv_actor::use().

◆ mutate_towards() [1/2]

bool Character::mutate_towards ( const trait_id mut)

Mutates toward the entered mutation, upgrading or removing conflicts if necessary.

Definition at line 1113 of file mutation.cpp.

1114{
1115 if( has_child_flag( mut ) ) {
1116 remove_child_flag( mut );
1117 return true;
1118 }
1119 const mutation_branch &mdata = mut.obj();
1120
1121 bool has_prereqs = false;
1122 bool prereq1 = false;
1123 bool prereq2 = false;
1124 std::vector<trait_id> canceltrait;
1125 std::vector<trait_id> prereq = mdata.prereqs;
1126 std::vector<trait_id> prereqs2 = mdata.prereqs2;
1127 std::vector<trait_id> cancel = mdata.cancels;
1128 std::vector<trait_id> same_type = get_mutations_in_types( mdata.types );
1129 std::vector<trait_id> all_prereqs = get_all_mutation_prereqs( mut );
1130
1131 // Check mutations of the same type - except for the ones we might need for pre-reqs
1132 for( const auto &consider : same_type ) {
1133 if( std::find( all_prereqs.begin(), all_prereqs.end(), consider ) == all_prereqs.end() ) {
1134 cancel.push_back( consider );
1135 }
1136 }
1137
1138 for( size_t i = 0; i < cancel.size(); i++ ) {
1139 if( !has_trait( cancel[i] ) ) {
1140 cancel.erase( cancel.begin() + i );
1141 i--;
1142 } else if( has_base_trait( cancel[i] ) ) {
1143 //If we have the trait, but it's a base trait, don't allow it to be removed normally
1144 canceltrait.push_back( cancel[i] );
1145 cancel.erase( cancel.begin() + i );
1146 i--;
1147 }
1148 }
1149
1150 for( size_t i = 0; i < cancel.size(); i++ ) {
1151 if( !cancel.empty() ) {
1152 trait_id removed = cancel[i];
1153 remove_mutation( removed );
1154 cancel.erase( cancel.begin() + i );
1155 i--;
1156 // This checks for cases where one trait knocks out several others
1157 // Probably a better way, but gets it Fixed Now--KA101
1158 return mutate_towards( mut );
1159 }
1160 }
1161
1162 for( size_t i = 0; ( !prereq1 ) && i < prereq.size(); i++ ) {
1163 if( has_trait( prereq[i] ) ) {
1164 prereq1 = true;
1165 }
1166 }
1167
1168 for( size_t i = 0; ( !prereq2 ) && i < prereqs2.size(); i++ ) {
1169 if( has_trait( prereqs2[i] ) ) {
1170 prereq2 = true;
1171 }
1172 }
1173
1174 if( prereq1 && prereq2 ) {
1175 has_prereqs = true;
1176 }
1177
1178 if( !has_prereqs && ( !prereq.empty() || !prereqs2.empty() ) ) {
1179 if( !prereq1 && !prereq.empty() ) {
1180 return mutate_towards( prereq );
1181 } else if( !prereq2 && !prereqs2.empty() ) {
1182 return mutate_towards( prereqs2 );
1183 }
1184 }
1185
1186 // Check for threshold mutation, if needed
1187 bool threshold = mdata.threshold;
1188 bool profession = mdata.profession;
1189 bool has_threshreq = false;
1190 std::vector<trait_id> threshreq = mdata.threshreq;
1191
1192 // It shouldn't pick a Threshold anyway--they're supposed to be non-Valid
1193 // and aren't categorized. This can happen if someone makes a threshold mutation into a prerequisite.
1194 if( threshold ) {
1195 add_msg_if_player( _( "You feel something straining deep inside you, yearning to be free…" ) );
1196 return false;
1197 }
1198 if( profession ) {
1199 // Profession picks fail silently
1200 return false;
1201 }
1202
1203 for( size_t i = 0; !has_threshreq && i < threshreq.size(); i++ ) {
1204 if( has_trait( threshreq[i] ) ) {
1205 has_threshreq = true;
1206 }
1207 }
1208
1209 // No crossing The Threshold by simply not having it
1210 if( !has_threshreq && !threshreq.empty() ) {
1211 add_msg_if_player( _( "You feel something straining deep inside you, yearning to be free…" ) );
1212 return false;
1213 }
1214
1215 // Check if one of the prerequisites that we have TURNS INTO this one
1216 trait_id replacing = trait_id::NULL_ID();
1217 prereq = mdata.prereqs; // Reset it
1218 for( auto &elem : prereq ) {
1219 if( has_trait( elem ) ) {
1220 const trait_id &pre = elem;
1221 const auto &p = pre.obj();
1222 for( size_t j = 0; !replacing && j < p.replacements.size(); j++ ) {
1223 if( p.replacements[j] == mut ) {
1224 replacing = pre;
1225 }
1226 }
1227 }
1228 }
1229
1230 // Loop through again for prereqs2
1231 trait_id replacing2 = trait_id::NULL_ID();
1232 prereq = mdata.prereqs2; // Reset it
1233 for( auto &elem : prereq ) {
1234 if( has_trait( elem ) ) {
1235 const trait_id &pre2 = elem;
1236 const auto &p = pre2.obj();
1237 for( size_t j = 0; !replacing2 && j < p.replacements.size(); j++ ) {
1238 if( p.replacements[j] == mut ) {
1239 replacing2 = pre2;
1240 }
1241 }
1242 }
1243 }
1244
1245 bool mutation_replaced = false;
1246
1247 game_message_type rating;
1248
1249 if( replacing ) {
1250 const auto &replace_mdata = replacing.obj();
1251 if( mdata.mixed_effect || replace_mdata.mixed_effect ) {
1252 rating = m_mixed;
1253 } else if( replace_mdata.points - mdata.points < 0 ) {
1254 rating = m_good;
1255 } else if( mdata.points - replace_mdata.points < 0 ) {
1256 rating = m_bad;
1257 } else {
1258 rating = m_neutral;
1259 }
1260 //  TODO: Limit this to visible mutations
1261 // TODO: In case invisible mutation turns into visible or vice versa
1262 // print only the visible mutation appearing/disappearing
1263 add_msg_player_or_npc( rating,
1264 _( "Your %1$s mutation turns into %2$s!" ),
1265 _( "<npcname>'s %1$s mutation turns into %2$s!" ),
1266 replace_mdata.name(), mdata.name() );
1267
1268 g->events().send<event_type::evolves_mutation>( getID(), replace_mdata.id, mdata.id );
1269 unset_mutation( replacing );
1270 mutation_replaced = true;
1271 }
1272 if( replacing2 ) {
1273 const auto &replace_mdata = replacing2.obj();
1274 if( mdata.mixed_effect || replace_mdata.mixed_effect ) {
1275 rating = m_mixed;
1276 } else if( replace_mdata.points - mdata.points < 0 ) {
1277 rating = m_good;
1278 } else if( mdata.points - replace_mdata.points < 0 ) {
1279 rating = m_bad;
1280 } else {
1281 rating = m_neutral;
1282 }
1283 add_msg_player_or_npc( rating,
1284 _( "Your %1$s mutation turns into %2$s!" ),
1285 _( "<npcname>'s %1$s mutation turns into %2$s!" ),
1286 replace_mdata.name(), mdata.name() );
1287 g->events().send<event_type::evolves_mutation>( getID(), replace_mdata.id, mdata.id );
1288 unset_mutation( replacing2 );
1289 mutation_replaced = true;
1290 }
1291 for( const auto &i : canceltrait ) {
1292 const auto &cancel_mdata = i.obj();
1293 if( mdata.mixed_effect || cancel_mdata.mixed_effect ) {
1294 rating = m_mixed;
1295 } else if( mdata.points < cancel_mdata.points ) {
1296 rating = m_bad;
1297 } else if( mdata.points > cancel_mdata.points ) {
1298 rating = m_good;
1299 } else if( mdata.points == cancel_mdata.points ) {
1300 rating = m_neutral;
1301 } else {
1302 rating = m_mixed;
1303 }
1304 // If this new mutation cancels a base trait, remove it and add the mutation at the same time
1305 add_msg_player_or_npc( rating,
1306 _( "Your innate %1$s trait turns into %2$s!" ),
1307 _( "<npcname>'s innate %1$s trait turns into %2$s!" ),
1308 cancel_mdata.name(), mdata.name() );
1309 g->events().send<event_type::evolves_mutation>( getID(), cancel_mdata.id, mdata.id );
1310 unset_mutation( i );
1311 mutation_replaced = true;
1312 }
1313 if( !mutation_replaced ) {
1314 if( mdata.mixed_effect ) {
1315 rating = m_mixed;
1316 } else if( mdata.points > 0 ) {
1317 rating = m_good;
1318 } else if( mdata.points < 0 ) {
1319 rating = m_bad;
1320 } else {
1321 rating = m_neutral;
1322 }
1323 // TODO: Limit to visible mutations
1324 add_msg_player_or_npc( rating,
1325 _( "You gain a mutation called %s!" ),
1326 _( "<npcname> gains a mutation called %s!" ),
1327 mdata.name() );
1328 g->events().send<event_type::gains_mutation>( getID(), mdata.id );
1329 }
1330
1331 set_mutation( mut );
1332
1335 return true;
1336}
static bool same_type(const std::list< item > &items)
void remove_child_flag(const trait_id &flag)
Removes the mutation's child flag from the player's list.
Definition: mutation.cpp:1496
void drench_mut_calc()
Recalculates mutation drench protection for all bodyparts (ignored/good/neutral stats)
Definition: character.cpp:7960
void set_highest_cat_level()
Recalculates mutation_category_level[] values for the player.
Definition: character.cpp:7937
@ cancel
Definition: craft_command.h:28
game_message_type
Definition: enums.h:252
static std::vector< trait_id > get_all_mutation_prereqs(const trait_id &id)
Definition: mutation.cpp:1081
std::vector< trait_id > get_mutations_in_types(const std::set< std::string > &ids)
trait_id id
Definition: mutation.h:76
bool threshold
Definition: mutation.h:83
std::set< std::string > types
Definition: mutation.h:259
bool profession
Definition: mutation.h:85
std::vector< trait_id > threshreq
Definition: mutation.h:258
bool mixed_effect
Definition: mutation.h:91

References _, Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), cancel, mutation_branch::cancels, drench_mut_calc(), evolves_mutation, detail::find(), g, gains_mutation, get_all_mutation_prereqs(), get_mutations_in_types(), getID(), has_base_trait(), has_child_flag(), has_trait(), mutation_branch::id, m_bad, m_good, m_mixed, m_neutral, mutation_branch::mixed_effect, mutate_towards(), mutation_branch::name(), string_id< mutation_branch >::NULL_ID(), string_id< T >::obj(), mutation_branch::points, mutation_branch::prereqs, mutation_branch::prereqs2, mutation_branch::profession, remove_child_flag(), remove_mutation(), same_type(), set_highest_cat_level(), set_mutation(), mutation_branch::threshold, mutation_branch::threshreq, mutation_branch::types, and unset_mutation().

◆ mutate_towards() [2/2]

bool Character::mutate_towards ( std::vector< trait_id muts,
int  num_tries = INT_MAX 
)

Mutates toward one of the given mutations, upgrading or removing conflicts if necessary.

Definition at line 1097 of file mutation.cpp.

1098{
1099 while( !muts.empty() && num_tries > 0 ) {
1100 int i = rng( 0, muts.size() - 1 );
1101
1102 if( mutate_towards( muts[i] ) ) {
1103 return true;
1104 }
1105
1106 muts.erase( muts.begin() + i );
1107 --num_tries;
1108 }
1109
1110 return false;
1111}

References mutate_towards(), and rng().

Referenced by mutate(), spell_effect::mutate(), mutate_category(), mutate_towards(), old_mutate(), and debug_menu::wishmutate().

◆ mutation_armor() [1/3]

resistances Character::mutation_armor ( bodypart_id  bp) const

Returns resistances on a body part provided by mutations.

Definition at line 6510 of file character.cpp.

6511{
6512 resistances res;
6513 for( const trait_id &iter : get_mutations() ) {
6514 res += iter->damage_resistance( bp->token );
6515 }
6516
6517 return res;
6518}

References get_mutations().

Referenced by get_all_armor_type(), get_armor_bash_base(), get_armor_bullet_base(), get_armor_cut_base(), get_armor_type(), mutation_armor(), and passive_absorb_hit().

◆ mutation_armor() [2/3]

float Character::mutation_armor ( bodypart_id  bp,
const damage_unit du 
) const

Definition at line 6525 of file character.cpp.

6526{
6527 return mutation_armor( bp ).get_effective_resist( du );
6528}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References resistances::get_effective_resist(), and mutation_armor().

◆ mutation_armor() [3/3]

float Character::mutation_armor ( bodypart_id  bp,
damage_type  dt 
) const

Definition at line 6520 of file character.cpp.

6521{
6522 return mutation_armor( bp ).type_resist( dt );
6523}
float type_resist(damage_type dt) const
Definition: damage.cpp:213

References mutation_armor(), and resistances::type_resist().

◆ mutation_attacks()

std::vector< special_attack > Character::mutation_attacks ( Creature t) const

Returns a vector of valid mutation attacks.

Unarmed increases chance of attacking with mutated body parts Dexterity increases chance of attacking with mutated body parts

Definition at line 1935 of file melee.cpp.

1936{
1937 std::vector<special_attack> ret;
1938
1939 std::string target = t.disp_name();
1940
1941 const body_part_set usable_body_parts = exclusive_flag_coverage( "ALLOWS_NATURAL_ATTACKS" );
1942 const int unarmed = get_skill_level( skill_unarmed );
1943
1944 for( const trait_id &pr : get_mutations() ) {
1945 const mutation_branch &branch = pr.obj();
1946 for( const mut_attack &mut_atk : branch.attacks_granted ) {
1947 // Covered body part
1948 if( mut_atk.bp != num_bp && !usable_body_parts.test( mut_atk.bp ) ) {
1949 continue;
1950 }
1951
1952 /** @EFFECT_UNARMED increases chance of attacking with mutated body parts */
1953 /** @EFFECT_DEX increases chance of attacking with mutated body parts */
1954
1955 // Calculate actor ability value to be compared against mutation attack difficulty and add debug message
1956 const int proc_value = get_dex() + unarmed;
1957 add_msg( m_debug, "%s proc chance: %d in %d", pr.c_str(), proc_value, mut_atk.chance );
1958 // If the mutation attack fails to proc, bail out
1959 if( !x_in_y( proc_value, mut_atk.chance ) ) {
1960 continue;
1961 }
1962
1963 // If player has any blocker, bail out
1964 if( std::any_of( mut_atk.blocker_mutations.begin(), mut_atk.blocker_mutations.end(),
1965 [this]( const trait_id & blocker ) {
1966 return has_trait( blocker );
1967 } ) ) {
1968 add_msg( m_debug, "%s not procing: blocked", pr.c_str() );
1969 continue;
1970 }
1971
1972 // Player must have all needed traits
1973 if( !std::all_of( mut_atk.required_mutations.begin(), mut_atk.required_mutations.end(),
1974 [this]( const trait_id & need ) {
1975 return has_trait( need );
1976 } ) ) {
1977 add_msg( m_debug, "%s not procing: unmet req", pr.c_str() );
1978 continue;
1979 }
1980
1981 special_attack tmp;
1982 // Ugly special case: player's strings have only 1 variable, NPC have 2
1983 // Can't use <npcname> here
1984 // TODO: Fix
1985 if( is_player() ) {
1986 tmp.text = string_format( _( mut_atk.attack_text_u ), target );
1987 } else {
1988 tmp.text = string_format( _( mut_atk.attack_text_npc ), name, target );
1989 }
1990
1991 // Attack starts here
1992 if( mut_atk.hardcoded_effect ) {
1993 tmp.damage = hardcoded_mutation_attack( *this, pr );
1994 } else {
1995 damage_instance dam = mut_atk.base_damage;
1996 damage_instance scaled = mut_atk.strength_damage;
1997 scaled.mult_damage( std::min<float>( 15.0f, get_str() ), true );
1998 dam.add( scaled );
1999
2000 tmp.damage = dam;
2001 }
2002
2003 if( tmp.damage.total_damage() > 0.0f ) {
2004 ret.emplace_back( tmp );
2005 } else {
2006 add_msg( m_debug, "%s not procing: zero damage", pr.c_str() );
2007 }
2008 }
2009 }
2010
2011 return ret;
2012}
static damage_instance hardcoded_mutation_attack(const Character &u, const trait_id &id)
Definition: melee.cpp:1881
float total_damage() const
Definition: damage.cpp:75
void add(const damage_instance &added_di)
Definition: damage.cpp:93
std::string attack_text_u
Text printed when the attack is proced by you.
Definition: mutation.h:39
std::set< trait_id > blocker_mutations
Need none of those to qualify for this attack.
Definition: mutation.h:45
std::set< trait_id > required_mutations
Need all of those to qualify for this attack.
Definition: mutation.h:43
int chance
Chance to proc is one_in( chance - dex - unarmed )
Definition: mutation.h:51
body_part bp
If not num_bp, this body part needs to be uncovered for the attack to proc.
Definition: mutation.h:48
damage_instance base_damage
Definition: mutation.h:53
bool hardcoded_effect
Should be true when and only when this attack needs hardcoded handling.
Definition: mutation.h:58
damage_instance strength_damage
Multiplied by strength and added to the above.
Definition: mutation.h:55
std::string attack_text_npc
As above, but for npc.
Definition: mutation.h:41
std::vector< mut_attack > attacks_granted
Attacks granted by this mutation.
Definition: mutation.h:248
std::string text
Definition: character.h:197
damage_instance damage
Definition: character.h:198

References _, damage_instance::add(), add_msg(), mut_attack::attack_text_npc, mut_attack::attack_text_u, mutation_branch::attacks_granted, mut_attack::base_damage, mut_attack::blocker_mutations, mut_attack::bp, mut_attack::chance, special_attack::damage, Creature::disp_name(), exclusive_flag_coverage(), get_dex(), get_mutations(), get_skill_level(), get_str(), mut_attack::hardcoded_effect, hardcoded_mutation_attack(), Creature::is_player(), m_debug, damage_instance::mult_damage(), name, num_bp, mut_attack::required_mutations, cata::hash64_detail::ret, skill_unarmed, mut_attack::strength_damage, string_format(), body_part_set::test(), special_attack::text, damage_instance::total_damage(), and x_in_y().

Referenced by perform_special_attacks().

◆ mutation_chances()

std::map< trait_id, float > Character::mutation_chances ( ) const

Calculate percentage chances for mutations.

Definition at line 752 of file mutation.cpp.

753{
754 bool force_bad = false;
755 const bool force_good = false;
757 force_bad = true;
758 }
759
760 int current_score = genetic_score( *this );
761 // 10/10/10/10 in stats, balanced traits, plus tip
762 int expected_score = 4 * 10 + 6;
763 int direction = expected_score - current_score;
764
765 // Duplicates allowed - they'll increase chances of change
766 std::vector<potential_mutation> potential;
767
768 for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
769 const trait_id &base_mutation = traits_iter.id;
770 const mutation_branch &base_mdata = traits_iter;
771 bool thresh_save = base_mdata.threshold;
772 bool prof_save = base_mdata.profession;
773 bool purify_save = !base_mdata.purifiable;
774 bool can_remove = !thresh_save && !prof_save && !purify_save;
775
776 if( has_trait( base_mutation ) ) {
777 for( const trait_id &mutation : base_mdata.replacements ) {
778 if( mutation->valid && mutation_ok( mutation, force_good, force_bad ) ) {
779 potential.emplace_back( base_mutation, mutation, 3 );
780 }
781 }
782
783 for( const trait_id &mutation : base_mdata.additions ) {
784 if( mutation->valid && mutation_ok( mutation, force_good, force_bad ) ) {
785 potential.emplace_back( trait_id::NULL_ID(), mutation, 3 );
786 }
787 }
788
789 // Removal or downgrade (if possible)
790 if( can_remove ) {
791 potential.emplace_back( base_mutation, trait_id::NULL_ID(), 2 );
792 }
793 } else {
794 // Addition from nothing
795 // Duplicates addition above, but that's OK, we need to handle dupes anyway
796 if( base_mutation->valid && mutation_ok( base_mutation, force_good, force_bad ) ) {
797 potential.emplace_back( trait_id::NULL_ID(), base_mutation, 1 );
798 }
799 }
800 }
801
802 // We need all mutation categories in here
803 std::map<std::string, int> padded_mut_cat_lvl = mutation_category_level;
804 for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
805 for( const std::string &cat : traits_iter.category ) {
806 // Will do nothing if it exists already
807 padded_mut_cat_lvl.insert( std::make_pair( cat, 0 ) );
808 }
809 }
810
811 const std::map<std::string, float> add_weighs =
812 calc_category_weights( padded_mut_cat_lvl, true );
813 const std::map<std::string, float> rem_weighs =
814 calc_category_weights( padded_mut_cat_lvl, false );
815
816 // Not normalized
817 std::map<trait_id, float> chances;
818
819 // Warning: has duplicates
820 for( const potential_mutation &pm : potential ) {
821 int cost_from = pm.from.is_valid() ? pm.from->cost : 0;
822 int cost_to = pm.to.is_valid() ? pm.to->cost : 0;
823 int score_diff = cost_to - cost_from;
824
825 if( pm.to.is_valid() ) {
826 float cat_mod = std::accumulate( pm.to->category.begin(), pm.to->category.end(), 0.0f,
827 [&add_weighs]( float m, const std::string & cat ) {
828 return std::max( m, add_weighs.at( cat ) );
829 } );
830 float c = score_difference_to_chance( direction + score_diff );
831 chances[pm.to] += c * cat_mod;
832 } else if( pm.from.is_valid() ) {
833 float cat_mod = std::accumulate( pm.from->category.begin(), pm.from->category.end(), 0.0f,
834 [&rem_weighs]( float m, const std::string & cat ) {
835 return std::min( m, rem_weighs.at( cat ) );
836 } );
837 float c = score_difference_to_chance( direction - score_diff );
838 chances[pm.from] += c * cat_mod;
839 }
840 }
841
842 return normalized_map( chances );
843}
direction
Definition: line.h:39
constexpr double c
Definition: magic.cpp:1032
static float score_difference_to_chance(float diff)
Definition: mutation.cpp:690
static T normalized_map(const T &ctn)
Definition: mutation.cpp:699
static int genetic_score(const Character &c)
Definition: mutation.cpp:683
static std::map< std::string, float > calc_category_weights(const std::map< std::string, int > &mcl, bool addition)
Definition: mutation.cpp:719
static const std::vector< mutation_branch > & get_all()
All known mutations.
bool purifiable
Definition: mutation.h:81
std::vector< trait_id > additions
Definition: mutation.h:262

References mutation_branch::additions, c, calc_category_weights(), genetic_score(), mutation_branch::get_all(), has_trait(), string_id< T >::id(), mutation_category_level, mutation_ok(), normalized_map(), string_id< mutation_branch >::NULL_ID(), mutation_branch::profession, mutation_branch::purifiable, mutation_branch::replacements, score_difference_to_chance(), mutation_branch::threshold, trait_CHAOTIC_BAD, and mutation_branch::valid.

Referenced by debug_menu::debug(), and mutate().

◆ mutation_effect()

void Character::mutation_effect ( const trait_id mut)

Handles things like removal of armor, etc.

Definition at line 258 of file mutation.cpp.

259{
260 if( mut == trait_GLASSJAW ) {
261 recalc_hp();
262
263 } else if( mut == trait_STR_ALPHA ) {
264 if( str_max < 16 ) {
265 str_max = 8 + str_max / 2;
266 }
267 apply_mods( mut, true );
268 recalc_hp();
269 } else if( mut == trait_DEX_ALPHA ) {
270 if( dex_max < 16 ) {
271 dex_max = 8 + dex_max / 2;
272 }
273 apply_mods( mut, true );
274 } else if( mut == trait_INT_ALPHA ) {
275 if( int_max < 16 ) {
276 int_max = 8 + int_max / 2;
277 }
278 apply_mods( mut, true );
279 } else if( mut == trait_INT_SLIME ) {
280 int_max *= 2; // Now, can you keep it? :-)
281
282 } else if( mut == trait_PER_ALPHA ) {
283 if( per_max < 16 ) {
284 per_max = 8 + per_max / 2;
285 }
286 apply_mods( mut, true );
287 } else {
288 apply_mods( mut, true );
289 }
290
292
293 const auto &branch = mut.obj();
294 if( branch.hp_modifier != 0.0f || branch.hp_modifier_secondary != 0.0f ||
295 branch.hp_adjustment != 0.0f ) {
296 recalc_hp();
297 }
298
299 remove_worn_items_with( [&]( item & armor ) {
300 static const std::string mutation_safe = "OVERSIZE";
301 if( armor.has_flag( mutation_safe ) ) {
302 return false;
303 }
304 if( !branch.conflicts_with_item( armor ) ) {
305 return false;
306 }
307
309 _( "Your %s is pushed off!" ),
310 _( "<npcname>'s %s is pushed off!" ),
311 armor.tname() );
312 get_map().add_item_or_charges( pos(), armor );
313 return true;
314 } );
315
316 if( branch.starts_active ) {
317 my_mutations[mut].powered = true;
318 }
319
320 on_mutation_gain( mut );
321}
std::list< item > remove_worn_items_with(std::function< bool(item &)> filter)
Similar to remove_items_with, but considers only worn items and not their content (item::contents is ...
Definition: character.cpp:2350
static const trait_id trait_PER_ALPHA("PER_ALPHA")
static const trait_id trait_STR_ALPHA("STR_ALPHA")
static const trait_id trait_GLASSJAW("GLASSJAW")
static const trait_id trait_DEX_ALPHA("DEX_ALPHA")
static const trait_id trait_INT_SLIME("INT_SLIME")
static const trait_id trait_INT_ALPHA("INT_ALPHA")

References _, Creature::add_msg_player_or_npc(), apply_mods(), dex_max, get_map(), item::has_flag(), int_max, m_bad, my_mutations, string_id< T >::obj(), on_mutation_gain(), per_max, pos(), recalc_hp(), recalculate_size(), remove_worn_items_with(), str_max, item::tname(), trait_DEX_ALPHA, trait_GLASSJAW, trait_INT_ALPHA, trait_INT_SLIME, trait_PER_ALPHA, and trait_STR_ALPHA.

Referenced by on_item_wear(), set_mutation(), and switch_mutations().

◆ mutation_loss_effect()

void Character::mutation_loss_effect ( const trait_id mut)

Handles what happens when you lose a mutation.

Definition at line 323 of file mutation.cpp.

324{
325 if( mut == trait_GLASSJAW ) {
326 recalc_hp();
327
328 } else if( mut == trait_STR_ALPHA ) {
329 apply_mods( mut, false );
330 if( str_max < 16 ) {
331 str_max = 2 * ( str_max - 8 );
332 }
333 recalc_hp();
334 } else if( mut == trait_DEX_ALPHA ) {
335 apply_mods( mut, false );
336 if( dex_max < 16 ) {
337 dex_max = 2 * ( dex_max - 8 );
338 }
339 } else if( mut == trait_INT_ALPHA ) {
340 apply_mods( mut, false );
341 if( int_max < 16 ) {
342 int_max = 2 * ( int_max - 8 );
343 }
344 } else if( mut == trait_INT_SLIME ) {
345 int_max /= 2; // In case you have a freak accident with the debug menu ;-)
346
347 } else if( mut == trait_PER_ALPHA ) {
348 apply_mods( mut, false );
349 if( per_max < 16 ) {
350 per_max = 2 * ( per_max - 8 );
351 }
352 } else {
353 apply_mods( mut, false );
354 }
355
357
358 const auto &branch = mut.obj();
359 if( branch.hp_modifier != 0.0f || branch.hp_modifier_secondary != 0.0f ||
360 branch.hp_adjustment != 0.0f ) {
361 recalc_hp();
362 }
363
364 on_mutation_loss( mut );
365}
void on_mutation_loss(const trait_id &mid)
Called when a mutation is lost.
Definition: character.cpp:9912

References apply_mods(), dex_max, int_max, string_id< T >::obj(), on_mutation_loss(), per_max, recalc_hp(), recalculate_size(), str_max, trait_DEX_ALPHA, trait_GLASSJAW, trait_INT_ALPHA, trait_INT_SLIME, trait_PER_ALPHA, and trait_STR_ALPHA.

Referenced by on_item_takeoff(), switch_mutations(), and unset_mutation().

◆ mutation_ok()

bool Character::mutation_ok ( const trait_id mutation,
bool  force_good,
bool  force_bad 
) const

Returns true if the player doesn't have the mutation or a conflicting one and it complies with the force typing.

Definition at line 639 of file mutation.cpp.

640{
641 if( !is_category_allowed( mutation->category ) ) {
642 return false;
643 }
644 if( mutation_branch::trait_is_blacklisted( mutation ) ) {
645 return false;
646 }
647 if( has_trait( mutation ) || has_child_flag( mutation ) ) {
648 // We already have this mutation or something that replaces it.
649 return false;
650 }
651
652 for( const bionic_id &bid : get_bionics() ) {
653 for( const trait_id &mid : bid->canceled_mutations ) {
654 if( mid == mutation ) {
655 return false;
656 }
657 }
658 }
659
660 const mutation_branch &mdata = mutation.obj();
661 if( force_bad && mdata.points > 0 ) {
662 // This is a good mutation, and we're due for a bad one.
663 return false;
664 }
665
666 if( force_good && mdata.points < 0 ) {
667 // This is a bad mutation, and we're due for a good one.
668 return false;
669 }
670
671 return true;
672}
bool is_category_allowed(const std::vector< std::string > &category) const
Returns true if this category of mutation is allowed.
Definition: mutation.cpp:373
std::vector< std::string > category
Definition: mutation.h:263
static bool trait_is_blacklisted(const trait_id &tid)
Check if the trait with the given ID is blacklisted.

References mutation_branch::category, get_bionics(), has_child_flag(), has_trait(), is_category_allowed(), string_id< T >::obj(), mutation_branch::points, and mutation_branch::trait_is_blacklisted().

Referenced by mutate_category(), mutation_chances(), and old_mutate().

◆ mutation_spend_resources()

void Character::mutation_spend_resources ( const trait_id mut)

Removes the appropriate costs (NOTE: will reapply mods & recalc sightlines in case of newly activated mutation).

Definition at line 1723 of file mutation.cpp.

1724{
1725 const mutation_branch &mdata = mut.obj();
1726 trait_data &tdata = my_mutations[mut];
1727 int cost = mdata.cost;
1728 if( tdata.powered && tdata.charge > 0 ) {
1729 // Already-on units just lose a bit of charge
1730 tdata.charge--;
1731 } else {
1732 // Not-on units, or those with zero charge, have to pay the power cost
1733 if( mdata.cooldown > 0 ) {
1734 tdata.charge = mdata.cooldown - 1;
1735 }
1736 if( mdata.hunger ) {
1737 // burn some energy
1738 mod_stored_kcal( -cost * 6 );
1739 }
1740 if( mdata.thirst ) {
1741 mod_thirst( cost );
1742 }
1743 if( mdata.fatigue ) {
1744 mod_fatigue( cost );
1745 }
1746
1747 // Handle stat changes from activation
1748 apply_mods( mut, true );
1750 }
1751}

References apply_mods(), Character::trait_data::charge, mutation_branch::cooldown, mutation_branch::cost, mutation_branch::fatigue, mutation_branch::hunger, mod_fatigue(), mod_stored_kcal(), mod_thirst(), my_mutations, string_id< T >::obj(), Character::trait_data::powered, recalc_sight_limits(), and mutation_branch::thirst.

Referenced by activate_mutation(), iexamine::ledge(), and game::vertical_move().

◆ mutation_value()

float Character::mutation_value ( const std::string &  val) const

Goes over all mutations, gets min and max of a value with given name.

Returns
min( 0, lowest ) + max( 0, highest )

Definition at line 6765 of file character.cpp.

6766{
6767 // Syntax similar to tuple get<n>()
6768 const auto found = mutation_value_map.find( val );
6769
6770 if( found == mutation_value_map.end() ) {
6771 debugmsg( "Invalid mutation value name %s", val );
6772 return 0.0f;
6773 } else {
6774 return found->second( cached_mutations );
6775 }
6776}
static const std::map< std::string, std::function< float(std::vector< const mutation_branch * >)> > mutation_value_map
Definition: character.cpp:6728

References cached_mutations, debugmsg, and mutation_value_map.

Referenced by attack_cost(), calc_needs_rates(), draw_speed_tab(), get_stamina_max(), healing_rate(), healing_rate_medicine(), hearing_ability(), is_immune_effect(), known_magic::mana_regen_rate(), known_magic::max_mana(), mend(), metabolic_rate_base(), overmap_sight_range(), read_speed(), recalc_hp(), player::recalc_speed_bonus(), reset_stats(), run_cost(), rust_rate(), swim_speed(), update_stamina(), visibility(), game::walk_move(), and weight_capacity().

◆ natural_attack_restricted_on()

bool Character::natural_attack_restricted_on ( const bodypart_id bp) const

Returns true if the character is wearing something on the entered body_part, ignoring items with the ALLOWS_NATURAL_ATTACKS flag.

Definition at line 1859 of file character.cpp.

1860{
1861 for( const item &i : worn ) {
1862 if( i.covers( bp->token ) && !i.has_flag( "ALLOWS_NATURAL_ATTACKS" ) &&
1863 !i.has_flag( "SEMITANGIBLE" ) &&
1864 !i.has_flag( "PERSONAL" ) && !i.has_flag( "AURA" ) ) {
1865 return true;
1866 }
1867 }
1868 return false;
1869}

References worn.

Referenced by roll_bash_damage(), roll_cut_damage(), and roll_stab_damage().

◆ nearby()

std::vector< item_location > Character::nearby ( const std::function< bool(const item *, const item *)> &  func,
int  radius = 1 
) const

Returns nearby items which match the provided predicate.

Definition at line 2255 of file character.cpp.

2257{
2258 std::vector<item_location> res;
2259
2260 visit_items( [&]( const item * e, const item * parent ) {
2261 if( func( e, parent ) ) {
2262 res.emplace_back( const_cast<Character &>( *this ), const_cast<item *>( e ) );
2263 }
2264 return VisitResponse::NEXT;
2265 } );
2266
2267 for( const auto &cur : map_selector( pos(), radius ) ) {
2268 cur.visit_items( [&]( const item * e, const item * parent ) {
2269 if( func( e, parent ) ) {
2270 res.emplace_back( cur, const_cast<item *>( e ) );
2271 }
2272 return VisitResponse::NEXT;
2273 } );
2274 }
2275
2276 for( const auto &cur : vehicle_selector( pos(), radius ) ) {
2277 cur.visit_items( [&]( const item * e, const item * parent ) {
2278 if( func( e, parent ) ) {
2279 res.emplace_back( cur, const_cast<item *>( e ) );
2280 }
2281 return VisitResponse::NEXT;
2282 } );
2283 }
2284
2285 return res;
2286}

References NEXT, pos(), and visitable< Character >::visit_items().

Referenced by bandolier_actor::reload(), and npc::within_boundaries_of_camp().

◆ normalize()

void Character::normalize ( )
overridevirtual

Calls Creature::normalize() nulls out the player's weapon Should only be called through player::normalize(), not on it's own!

Reimplemented from Creature.

Reimplemented in player.

Definition at line 3473 of file character.cpp.

3474{
3476
3477 martial_arts_data->reset_style();
3479
3480 set_body();
3481 recalc_hp();
3482}
virtual void normalize()
Recreates the Creature from scratch.
Definition: creature.cpp:121

References martial_arts_data, Creature::normalize(), recalc_hp(), Creature::set_body(), calendar::start_of_cataclysm, and weapon.

Referenced by player::normalize().

◆ num_bionics()

int Character::num_bionics ( ) const

Returns the size of my_bionics[].

Definition at line 2623 of file bionics.cpp.

2624{
2625 return my_bionics->size();
2626}

References my_bionics.

Referenced by conditional_t< T >::set_has_bionics().

◆ nutrition_for()

int Character::nutrition_for ( const item comest) const

Handles the nutrition value for a comestible.

Definition at line 460 of file consumption.cpp.

461{
463}
static constexpr float kcal_per_nutr
1 nutr ~= 8.7kcal (1 nutr/5min = 288 nutr/day at 2500kcal/day)
Definition: itype.h:180
int kcal
amount of kcal this food has
Definition: stomach.h:18

References compute_effective_nutrients(), nutrients::kcal, and islot_comestible::kcal_per_nutr.

Referenced by iuse::blech(), can_eat(), consume_effects(), npc::decide_needs(), player::eat(), iuse::plantblech(), and npc::value().

◆ old_mutate()

void Character::old_mutate ( )
private

Definition at line 887 of file mutation.cpp.

888{
889 bool force_bad = one_in( 3 );
890 bool force_good = false;
891 if( has_trait( trait_ROBUST ) && force_bad ) {
892 // Robust Genetics gives you a 33% chance for a good mutation,
893 // instead of the 33% chance of a bad one.
894 force_bad = false;
895 force_good = true;
896 }
898 force_bad = true;
899 force_good = false;
900 }
901
902 // Determine the highest mutation category
903 std::string cat = get_highest_category();
904
905 if( !is_category_allowed( cat ) ) {
906 cat.clear();
907 }
908
909 // See if we should upgrade/extend an existing mutation...
910 std::vector<trait_id> upgrades;
911
912 // ... or remove one that is not in our highest category
913 std::vector<trait_id> downgrades;
914
915 // For each mutation...
916 for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
917 const trait_id &base_mutation = traits_iter.id;
918 const mutation_branch &base_mdata = traits_iter;
919 bool thresh_save = base_mdata.threshold;
920 bool prof_save = base_mdata.profession;
921 // are we unpurifiable? (saved from mutating away)
922 bool purify_save = !base_mdata.purifiable;
923
924 // ...that we have...
925 if( has_trait( base_mutation ) ) {
926 // ...consider the mutations that replace it.
927 for( const trait_id &mutation : base_mdata.replacements ) {
928 bool valid_ok = mutation->valid;
929
930 if( ( mutation_ok( mutation, force_good, force_bad ) ) &&
931 ( valid_ok ) ) {
932 upgrades.push_back( mutation );
933 }
934 }
935
936 // ...consider the mutations that add to it.
937 for( const trait_id &mutation : base_mdata.additions ) {
938 bool valid_ok = mutation->valid;
939
940 if( ( mutation_ok( mutation, force_good, force_bad ) ) &&
941 ( valid_ok ) ) {
942 upgrades.push_back( mutation );
943 }
944 }
945
946 // ...consider whether its in our highest category
947 if( has_trait( base_mutation ) && !has_base_trait( base_mutation ) ) {
948 // Starting traits don't count toward categories
949 std::vector<trait_id> group = mutations_category[cat];
950 bool in_cat = false;
951 for( const trait_id &elem : group ) {
952 if( elem == base_mutation ) {
953 in_cat = true;
954 break;
955 }
956 }
957
958 // mark for removal
959 // no removing Thresholds/Professions this way!
960 // unpurifiable traits also cannot be purified
961 if( !in_cat && !thresh_save && !prof_save && !purify_save ) {
962 if( one_in( 4 ) ) {
963 downgrades.push_back( base_mutation );
964 }
965 }
966 }
967 }
968 }
969
970 // Preliminary round to either upgrade or remove existing mutations
971 if( one_in( 2 ) ) {
972 if( !upgrades.empty() ) {
973 // (upgrade count) chances to pick an upgrade, 4 chances to pick something else.
974 size_t roll = rng( 0, upgrades.size() + 4 );
975 if( roll < upgrades.size() ) {
976 // We got a valid upgrade index, so use it and return.
977 mutate_towards( upgrades[roll] );
978 return;
979 }
980 }
981 } else {
982 // Remove existing mutations that don't fit into our category
983 if( !downgrades.empty() && !cat.empty() ) {
984 size_t roll = rng( 0, downgrades.size() + 4 );
985 if( roll < downgrades.size() ) {
986 remove_mutation( downgrades[roll] );
987 return;
988 }
989 }
990 }
991
992 std::vector<trait_id> valid; // Valid mutations
993 bool first_pass = true;
994
995 do {
996 // If we tried once with a non-NULL category, and couldn't find anything valid
997 // there, try again with empty category
998 // CHAOTIC_BAD lets the game pull from any category by default
999 if( !first_pass || has_trait( trait_CHAOTIC_BAD ) ) {
1000 cat.clear();
1001 }
1002
1003 if( cat.empty() ) {
1004 // Pull the full list
1005 for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
1006 if( traits_iter.valid && is_category_allowed( traits_iter.category ) ) {
1007 valid.push_back( traits_iter.id );
1008 }
1009 }
1010 } else {
1011 // Pull the category's list
1012 valid = mutations_category[cat];
1013 }
1014
1015 // Remove anything we already have, that we have a child of, or that
1016 // goes against our intention of a good/bad mutation
1017 for( size_t i = 0; i < valid.size(); i++ ) {
1018 if( ( !mutation_ok( valid[i], force_good, force_bad ) ) ||
1019 ( !valid[i]->valid ) ) {
1020 valid.erase( valid.begin() + i );
1021 i--;
1022 }
1023 }
1024
1025 if( valid.empty() ) {
1026 // So we won't repeat endlessly
1027 first_pass = false;
1028 }
1029 } while( valid.empty() && !cat.empty() );
1030
1031 if( valid.empty() ) {
1032 // Couldn't find anything at all!
1033 return;
1034 }
1035
1036 if( mutate_towards( random_entry( valid ) ) ) {
1037 return;
1038 } else {
1039 // if mutation failed (errors, post-threshold pick), try again once.
1040 mutate_towards( random_entry( valid ) );
1041 }
1042}
std::string get_highest_category() const
Returns the highest mutation category.
Definition: character.cpp:7984
group
Definition: sounds.h:125

References mutation_branch::additions, mutation_branch::get_all(), get_highest_category(), has_base_trait(), has_trait(), string_id< T >::id(), is_category_allowed(), mutate_towards(), mutation_ok(), mutations_category, one_in(), mutation_branch::profession, mutation_branch::purifiable, random_entry(), remove_mutation(), mutation_branch::replacements, rng(), mutation_branch::threshold, trait_CHAOTIC_BAD, trait_ROBUST, and mutation_branch::valid.

Referenced by mutate().

◆ on_damage_of_type()

void Character::on_damage_of_type ( int  adjusted_damage,
damage_type  type,
const bodypart_id bp 
)
overrideprotectedvirtual

Reimplemented from Creature.

Definition at line 4511 of file character.cpp.

4512{
4513 // Electrical damage has a chance to temporarily incapacitate bionics in the damaged body_part.
4514 if( type == DT_ELECTRIC ) {
4515 const time_duration min_disable_time = 10_turns * adjusted_damage;
4516 for( bionic &i : *my_bionics ) {
4517 if( !i.powered ) {
4518 // Unpowered bionics are protected from power surges.
4519 continue;
4520 }
4521 const auto &info = i.info();
4522 if( info.has_flag( STATIC( flag_str_id( "BIONIC_SHOCKPROOF" ) ) )
4523 || info.has_flag( STATIC( flag_str_id( "BIONIC_FAULTY" ) ) ) ) {
4524 continue;
4525 }
4526 const std::map<bodypart_str_id, int> &bodyparts = info.occupied_bodyparts;
4527 if( bodyparts.find( bp.id() ) != bodyparts.end() ) {
4528 const int bp_hp = get_part_hp_cur( bp );
4529 // The chance to incapacitate is as high as 50% if the attack deals damage equal to one third of the body part's current health.
4530 if( x_in_y( adjusted_damage * 3, bp_hp ) && one_in( 2 ) ) {
4531 if( i.incapacitated_time == 0_turns ) {
4532 add_msg_if_player( m_bad, _( "Your %s bionic shorts out!" ), info.name );
4533 }
4534 i.incapacitated_time += rng( min_disable_time, 10 * min_disable_time );
4535 }
4536 }
4537 }
4538 }
4539}
#define STATIC(expr)
The purpose of this macro is to provide a concise syntax for creation of inline literals (std::string...
Definition: make_static.h:24
string_id< json_flag > flag_str_id
Definition: type_id.h:203

References _, Creature::add_msg_if_player(), DT_ELECTRIC, Creature::get_part_hp_cur(), int_id< T >::id(), m_bad, my_bionics, one_in(), rng(), STATIC, type, and x_in_y().

◆ on_effect_int_change()

void Character::on_effect_int_change ( const efftype_id effect_type,
int  intensity,
const bodypart_str_id bp 
)
overridevirtual

Called when effect intensity has been changed.

Reimplemented from Creature.

Definition at line 9891 of file character.cpp.

9893{
9894 // Adrenaline can reduce perceived pain (or increase it when you enter comedown).
9895 // See @ref get_perceived_pain()
9897 // Note that calling this does no harm if it wasn't changed.
9898 on_stat_change( "perceived_pain", get_perceived_pain() );
9899 }
9900
9901 morale->on_effect_int_change( effect_type, intensity, bp );
9902}

References effect_adrenaline, Creature::get_perceived_pain(), morale, and on_stat_change().

Referenced by load(), and Creature::load().

◆ on_hit()

void Character::on_hit ( Creature source,
bodypart_id  bp_hit,
float  difficulty,
dealt_projectile_attack const *  proj 
)
overridevirtual

This creature just got hit by an attack - possibly special/ranged attack - from source.

Players should train dodge, possibly counter-attack somehow.

Implements Creature.

Reimplemented in player.

Definition at line 8411 of file character.cpp.

8413{
8414 enchantment_cache->cast_hit_me( *this, source );
8415}

References enchantment_cache.

Referenced by melee_attack(), and player::on_hit().

◆ on_hurt()

void Character::on_hurt ( Creature source,
bool  disturb = true 
)

Handles effects that happen when the player is damaged and aware of the fact.

Definition at line 8702 of file character.cpp.

8703{
8705 ( get_part_hp_cur( bodypart_id( "head" ) ) < 25 ||
8706 get_part_hp_cur( bodypart_id( "torso" ) ) < 15 ) ) {
8707 add_effect( effect_adrenaline, 20_minutes );
8708 }
8709
8710 if( disturb ) {
8712 wake_up();
8713 }
8714 if( !is_npc() && !has_effect( effect_narcosis ) ) {
8715 if( source != nullptr ) {
8716 g->cancel_activity_or_ignore_query( distraction_type::attacked,
8717 string_format( _( "You were attacked by %s!" ),
8718 source->disp_name() ) );
8719 } else {
8720 g->cancel_activity_or_ignore_query( distraction_type::attacked, _( "You were hurt!" ) );
8721 }
8722 }
8723 }
8724
8725 if( is_dead_state() ) {
8726 set_killer( source );
8727 }
8728}
static const efftype_id effect_narcosis("narcosis")
static const trait_id trait_ADRENALINE("ADRENALINE")
void wake_up()
Removes "sleep" and "lying_down".
Definition: character.cpp:7687

References _, Creature::add_effect(), attacked, Creature::disp_name(), effect_adrenaline, effect_narcosis, effect_sleep, g, Creature::get_part_hp_cur(), Creature::has_effect(), has_trait(), Creature::is_dead_state(), Creature::is_npc(), Creature::set_killer(), string_format(), trait_ADRENALINE, and wake_up().

Referenced by apply_damage(), deal_damage(), and hurtall().

◆ on_item_takeoff()

void Character::on_item_takeoff ( const item it)

Called when an item is taken off.

Definition at line 9878 of file character.cpp.

9879{
9880 for( const trait_id &mut : it.mutations_from_wearing( *this ) ) {
9881 mutation_loss_effect( mut );
9884 if( get_stamina() > get_stamina_max() ) {
9886 }
9887 }
9888 morale->on_item_takeoff( it );
9889}
void mutation_loss_effect(const trait_id &mut)
Handles what happens when you lose a mutation.
Definition: mutation.cpp:323
std::vector< trait_id > mutations_from_wearing(const Character &guy) const
Definition: item.cpp:8914

References calc_encumbrance(), get_stamina(), get_stamina_max(), morale, mutation_loss_effect(), item::mutations_from_wearing(), recalc_sight_limits(), and set_stamina().

Referenced by item::on_takeoff().

◆ on_item_wear()

void Character::on_item_wear ( const item it)

Called when an item is worn.

Definition at line 9863 of file character.cpp.

9864{
9865 for( const trait_id &mut : it.mutations_from_wearing( *this ) ) {
9866 mutation_effect( mut );
9869
9870 // If the stamina is higher than the max (Languorous), set it back to max
9871 if( get_stamina() > get_stamina_max() ) {
9873 }
9874 }
9875 morale->on_item_wear( it );
9876}
void mutation_effect(const trait_id &mut)
Handles things like removal of armor, etc.
Definition: mutation.cpp:258

References calc_encumbrance(), get_stamina(), get_stamina_max(), morale, mutation_effect(), item::mutations_from_wearing(), recalc_sight_limits(), and set_stamina().

Referenced by debug_menu::character_edit_menu(), load(), and item::on_wear().

◆ on_mutation_gain()

void Character::on_mutation_gain ( const trait_id mid)

Called when a mutation is gained.

Definition at line 9904 of file character.cpp.

9905{
9906 morale->on_mutation_gain( mid );
9907 magic->on_mutation_gain( mid, *this );
9908 update_type_of_scent( mid );
9909 recalculate_enchantment_cache(); // mutations can have enchantments
9910}

References magic, morale, recalculate_enchantment_cache(), and update_type_of_scent().

Referenced by add_bionic(), known_magic::learn_spell(), load(), and mutation_effect().

◆ on_mutation_loss()

void Character::on_mutation_loss ( const trait_id mid)

Called when a mutation is lost.

Definition at line 9912 of file character.cpp.

9913{
9914 morale->on_mutation_loss( mid );
9915 magic->on_mutation_loss( mid );
9916 update_type_of_scent( mid, false );
9917 recalculate_enchantment_cache(); // mutations can have enchantments
9918}

References magic, morale, recalculate_enchantment_cache(), and update_type_of_scent().

Referenced by mutation_loss_effect().

◆ on_stat_change()

void Character::on_stat_change ( const std::string &  stat,
int  value 
)
overridevirtual

Called when a stat is changed.

Reimplemented from Creature.

Definition at line 9920 of file character.cpp.

9921{
9922 morale->on_stat_change( stat, value );
9923}

References morale.

Referenced by load(), Creature::load(), on_effect_int_change(), set_fatigue(), player::set_pain(), set_painkiller(), and set_thirst().

◆ on_worn_item_washed()

void Character::on_worn_item_washed ( const item it)

Called when an item is washed.

Definition at line 9856 of file character.cpp.

9857{
9858 if( is_worn( it ) ) {
9859 morale->on_worn_item_washed( it );
9860 }
9861}

References is_worn(), and morale.

Referenced by wash_activity_actor::finish().

◆ operator=() [1/2]

Character & Character::operator= ( Character &&  )
protecteddefault

◆ operator=() [2/2]

Character & Character::operator= ( const Character )
delete

◆ overmap_los()

bool Character::overmap_los ( const tripoint_abs_omt omt,
int  sight_points 
)

Returns true if overmap tile is within player line-of-sight.

Definition at line 748 of file character.cpp.

749{
751 const point_rel_omt offset = omt.xy() - ompos.xy();
752 if( offset.x() < -sight_points || offset.x() > sight_points ||
753 offset.y() < -sight_points || offset.y() > sight_points ) {
754 // Outside maximum sight range
755 return false;
756 }
757
758 // TODO: fix point types
759 const std::vector<tripoint> line = line_to( ompos.raw(), omt.raw(), 0, 0 );
760 for( size_t i = 0; i < line.size() && sight_points >= 0; i++ ) {
761 const tripoint &pt = line[i];
762 const oter_id &ter = overmap_buffer.ter( tripoint_abs_omt( pt ) );
763 sight_points -= static_cast<int>( ter->get_see_cost() );
764 if( sight_points < 0 ) {
765 return false;
766 }
767 }
768 return true;
769}
constexpr auto & x()
Definition: coordinates.h:118
constexpr Point & raw()
Definition: coordinates.h:111
constexpr auto & y()
Definition: coordinates.h:124
constexpr auto xy() const
Definition: coordinates.h:130
std::vector< coords::coord_point< Point, Origin, Scale > > line_to(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:548
constexpr scale omt
Definition: coordinates.h:32
unsigned char get_see_cost() const
Definition: omdata.h:230

References oter_t::get_see_cost(), global_omt_location(), line(), line_to(), coords::omt, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), overmapbuffer::ter(), coords::coord_point< Point, Origin, Scale >::x(), coords::coord_point< Point, Origin, Scale >::xy(), and coords::coord_point< Point, Origin, Scale >::y().

Referenced by overmap_ui::draw_ascii(), overmap_ui::draw_om_sidebar(), and overmap_ui::draw_overmap_chunk().

◆ overmap_sight_range()

int Character::overmap_sight_range ( int  light_level) const

Returns the distance the player can see on the overmap.

Definition at line 771 of file character.cpp.

772{
773 int sight = sight_range( light_level );
774 if( sight < SEEX ) {
775 return 0;
776 }
777 if( sight <= SEEX * 4 ) {
778 return ( sight / ( SEEX / 2 ) );
779 }
780
781 sight = 6;
782 // The higher your perception, the farther you can see.
783 sight += static_cast<int>( get_per() / 2 );
784 // The higher up you are, the farther you can see.
785 sight += std::max( 0, posz() ) * 2;
786 // Mutations like Scout and Topographagnosia affect how far you can see.
787 sight += mutation_value( "overmap_sight" );
788
789 float multiplier = mutation_value( "overmap_multiplier" );
790 // Binoculars double your sight range.
791 const bool has_optic = ( has_item_with_flag( "ZOOM" ) || has_bionic( bio_eye_optic ) ||
792 ( is_mounted() &&
793 mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) );
794 if( has_optic ) {
795 multiplier += 1;
796 }
797
798 sight = std::round( sight * multiplier );
799 return std::max( sight, 3 );
800}
static const bionic_id bio_eye_optic("bio_eye_optic")
int posz() const override
Definition: character.h:787
int sight_range(int light_level) const override
Returns the player's sight range.
Definition: character.cpp:719
static constexpr int SEEX
@ MF_MECH_RECON_VISION
Definition: mtype.h:117

References bio_eye_optic, get_per(), has_bionic(), has_item_with_flag(), is_mounted(), MF_MECH_RECON_VISION, mounted_creature, mutation_value(), posz(), SEEX, and sight_range().

Referenced by overmap_ui::draw_ascii(), overmap_ui::draw_om_sidebar(), overmap_ui::draw_overmap_chunk(), and game::update_overmap_seen().

◆ passive_absorb_hit()

void Character::passive_absorb_hit ( const bodypart_id bp,
damage_unit du 
) const

Check for relevant passive, non-clothing that can absorb damage, and reduce by specified damage unit.

Only flat bonuses are checked here. Multiplicative ones are checked in player::absorb_hit. The damage amount will never be reduced to less than 0. This is called from player::absorb_hit

Definition at line 8058 of file character.cpp.

8059{
8060 // >0 check because some mutations provide negative armor
8061 // Thin skin check goes before subdermal armor plates because SUBdermal
8062 if( du.amount > 0.0f ) {
8063 // HACK: Get rid of this as soon as CUT and STAB are split
8064 if( du.type == DT_STAB ) {
8065 damage_unit du_copy = du;
8066 du_copy.type = DT_CUT;
8067 du.amount -= mutation_armor( bp, du_copy );
8068 } else {
8069 du.amount -= mutation_armor( bp, du );
8070 }
8071 }
8072 du.amount -= bionic_armor_bonus( bp, du.type ); //Check for passive armor bionics
8073 du.amount -= mabuff_armor_bonus( du.type );
8074 du.amount = std::max( 0.0f, du.amount );
8075}
int mabuff_armor_bonus(damage_type type) const
Returns the armor bonus against given type from martial arts buffs.
float bionic_armor_bonus(const bodypart_id &bp, damage_type dt) const
Check for passive bionics that provide armor, and returns the armor bonus This is called from player:...
Definition: character.cpp:8371

References damage_unit::amount, bionic_armor_bonus(), DT_CUT, DT_STAB, mabuff_armor_bonus(), mutation_armor(), and damage_unit::type.

Referenced by absorb_hit(), and player::immune_to().

◆ passive_power_gen()

void Character::passive_power_gen ( int  b)

Passively produce power from PERPETUAL fuel.

Definition at line 1313 of file bionics.cpp.

1314{
1315 const bionic &bio = ( *my_bionics )[b];
1316 const float passive_fuel_efficiency = bio.info().passive_fuel_efficiency;
1317 if( bio.info().fuel_opts.empty() || bio.is_this_fuel_powered( fuel_type_muscle ) ||
1318 passive_fuel_efficiency == 0.0 ) {
1319 return;
1320 }
1321 const float effective_passive_efficiency = get_effective_efficiency( b, passive_fuel_efficiency );
1322 const std::vector<itype_id> &fuel_available = get_fuel_available( bio.id );
1323 map &here = get_map();
1324
1325 for( const itype_id &fuel : fuel_available ) {
1326 const item &tmp_fuel = item( fuel );
1327 const int fuel_energy = tmp_fuel.fuel_energy();
1328 if( !tmp_fuel.has_flag( flag_PERPETUAL ) ) {
1329 continue;
1330 }
1331
1332 if( fuel == fuel_type_sun_light ) {
1333 const double modifier = g->natural_light_level( pos().z ) / default_daylight_level();
1334 mod_power_level( units::from_kilojoule( fuel_energy ) * modifier * effective_passive_efficiency );
1335 } else if( fuel == fuel_type_wind ) {
1336 int vehwindspeed = 0;
1337 const optional_vpart_position vp = here.veh_at( pos() );
1338 if( vp ) {
1339 // vehicle velocity in mph
1340 vehwindspeed = std::abs( vp->vehicle().velocity / 100 );
1341 }
1343 const double windpower = get_local_windpower( weather.windspeed + vehwindspeed,
1344 overmap_buffer.ter( global_omt_location() ), pos(), weather.winddirection,
1345 g->is_sheltered( pos() ) );
1346 mod_power_level( units::from_kilojoule( fuel_energy ) * windpower * effective_passive_efficiency );
1347 } else {
1348 mod_power_level( units::from_kilojoule( fuel_energy ) * effective_passive_efficiency );
1349 }
1350
1351 heat_emission( b, fuel_energy );
1352 if( bio.info().power_gen_emission ) {
1353 here.emit_field( pos(), bio.info().power_gen_emission );
1354 }
1355 }
1356}
float passive_fuel_efficiency
Fraction of fuel energy passively converted to bionic power.
Definition: bionics.h:69

References b, default_daylight_level(), map::emit_field(), flag_PERPETUAL(), units::from_kilojoule(), item::fuel_energy(), bionic_data::fuel_opts, fuel_type_muscle, fuel_type_sun_light, fuel_type_wind, g, get_effective_efficiency(), get_fuel_available(), get_local_windpower(), get_map(), get_weather(), global_omt_location(), item::has_flag(), heat_emission(), bionic::id, bionic::info(), bionic::is_this_fuel_powered(), mod_power_level(), overmap_buffer, bionic_data::passive_fuel_efficiency, pos(), bionic_data::power_gen_emission, overmapbuffer::ter(), and map::veh_at().

Referenced by process_bionic().

◆ perform_install()

void Character::perform_install ( bionic_id  bid,
bionic_id  upbid,
int  difficulty,
int  success,
int  pl_skill,
const std::string &  installer_name,
const std::vector< trait_id > &  trait_to_rem 
)

Success or failure of installation happens here.

Definition at line 2323 of file bionics.cpp.

2326{
2327
2328 g->events().send<event_type::installs_cbm>( getID(), bid );
2329 if( upbid != bionic_id( "" ) ) {
2330 remove_bionic( upbid );
2331 //~ %1$s - name of the bionic to be upgraded (inferior), %2$s - name of the upgraded bionic (superior).
2332 add_msg( m_good, _( "Upgraded %1$s to %2$s." ),
2333 upbid.obj().name, bid.obj().name );
2334 } else {
2335 //~ %s - name of the bionic.
2336 add_msg( m_good, _( "Installed %s." ), bid.obj().name );
2337 }
2338
2339 add_bionic( bid );
2340
2341 if( !trait_to_rem.empty() ) {
2342 for( const trait_id &tid : trait_to_rem ) {
2343 if( has_trait( tid ) ) {
2344 remove_mutation( tid );
2345 }
2346 }
2347 }
2348 if( success <= 0 ) {
2349 g->events().send<event_type::fails_to_install_cbm>( getID(), bid );
2350
2351 // for chance_of_success calculation, shift skill down to a float between ~0.4 - 30
2352 float adjusted_skill = static_cast<float>( pl_skill ) - std::min( static_cast<float>( 40 ),
2353 static_cast<float>( pl_skill ) - static_cast<float>( pl_skill ) / static_cast<float>
2354 ( 10.0 ) );
2355 bionics_install_failure( installer_name, difficulty, success, adjusted_skill );
2356 }
2357 get_map().invalidate_map_cache( g->get_levz() );
2358}
void remove_bionic(const bionic_id &b)
Removes a bionic from my_bionics[].
Definition: bionics.cpp:2586
void bionics_install_failure(const std::string &installer, int difficulty, int success, float adjusted_skill)
Definition: bionics.cpp:2400
void invalidate_map_cache(const int zlev)
Definition: map.h:471
@ fails_to_install_cbm

References _, add_bionic(), add_msg(), bionic_id, bionics_install_failure(), fails_to_install_cbm, g, get_map(), getID(), has_trait(), installs_cbm, map::invalidate_map_cache(), m_good, bionic_data::name, string_id< T >::obj(), remove_bionic(), remove_mutation(), and behavior::success.

Referenced by install_bionics(), and activity_handlers::operation_do_turn().

◆ perform_special_attacks()

void Character::perform_special_attacks ( Creature t,
dealt_damage_instance dealt_dam 
)

Performs special attacks and their effects (poisonous, stinger, etc.)

Definition at line 1766 of file melee.cpp.

1767{
1768 std::vector<special_attack> special_attacks = mutation_attacks( t );
1769
1770 bool practiced = false;
1771 for( const auto &att : special_attacks ) {
1772 if( t.is_dead_state() ) {
1773 break;
1774 }
1775
1776 // TODO: Make this hit roll use unarmed skill, not weapon skill + weapon to_hit
1777 int hit_spread = t.deal_melee_attack( this, hit_roll() * 0.8 );
1778 if( hit_spread >= 0 ) {
1779 t.deal_melee_hit( this, hit_spread, false, att.damage, dealt_dam );
1780 if( !practiced ) {
1781 // Practice unarmed, at most once per combo
1782 practiced = true;
1783 as_player()->practice( skill_unarmed, rng( 0, 10 ) );
1784 }
1785 }
1786 int dam = dealt_dam.total_damage();
1787 if( dam > 0 ) {
1788 player_hit_message( this, att.text, t, dam );
1789 }
1790 }
1791}
std::vector< special_attack > mutation_attacks(Creature &t) const
Returns a vector of valid mutation attacks.
Definition: melee.cpp:1935

References Creature::as_player(), Creature::deal_melee_attack(), Creature::deal_melee_hit(), hit_roll(), Creature::is_dead_state(), mutation_attacks(), player_hit_message(), player::practice(), rng(), skill_unarmed, and dealt_damage_instance::total_damage().

Referenced by melee_attack().

◆ perform_technique()

void Character::perform_technique ( const ma_technique technique,
Creature t,
damage_instance di,
int &  move_cost 
)
Intelligence slightly increases chance to learn techniques when using CQB bionic

Definition at line 1366 of file melee.cpp.

1368{
1369 add_msg( m_debug, "dmg before tec:" );
1370 print_damage_info( di );
1371
1372 for( damage_unit &du : di.damage_units ) {
1373 // TODO: Allow techniques to add more damage types to attacks
1374 if( du.amount <= 0 ) {
1375 continue;
1376 }
1377
1378 du.amount += technique.damage_bonus( *this, du.type );
1379 du.damage_multiplier *= technique.damage_multiplier( *this, du.type );
1380 du.res_pen += technique.armor_penetration( *this, du.type );
1381 }
1382
1383 add_msg( m_debug, "dmg after tec:" );
1384 print_damage_info( di );
1385
1386 move_cost *= technique.move_cost_multiplier( *this );
1387 move_cost += technique.move_cost_penalty( *this );
1388
1389 if( technique.down_dur > 0 ) {
1390 t.add_effect( effect_downed, rng( 1_turns, time_duration::from_turns( technique.down_dur ) ) );
1392 if( bash.amount > 0 ) {
1393 bash.amount += 3;
1394 }
1395 }
1396
1397 if( technique.side_switch ) {
1398 const tripoint b = t.pos();
1399 int newx;
1400 int newy;
1401
1402 if( b.x > posx() ) {
1403 newx = posx() - 1;
1404 } else if( b.x < posx() ) {
1405 newx = posx() + 1;
1406 } else {
1407 newx = b.x;
1408 }
1409
1410 if( b.y > posy() ) {
1411 newy = posy() - 1;
1412 } else if( b.y < posy() ) {
1413 newy = posy() + 1;
1414 } else {
1415 newy = b.y;
1416 }
1417
1418 const tripoint &dest = tripoint( newx, newy, b.z );
1419 if( g->is_empty( dest ) ) {
1420 t.setpos( dest );
1421 }
1422 }
1423
1424 if( technique.stun_dur > 0 && !technique.powerful_knockback ) {
1425 t.add_effect( effect_stunned, rng( 1_turns, time_duration::from_turns( technique.stun_dur ) ) );
1426 }
1427
1428 if( technique.knockback_dist ) {
1429 const tripoint prev_pos = t.pos(); // track target startpoint for knockback_follow
1430 const int kb_offset_x = rng( -technique.knockback_spread, technique.knockback_spread );
1431 const int kb_offset_y = rng( -technique.knockback_spread, technique.knockback_spread );
1432 tripoint kb_point( posx() + kb_offset_x, posy() + kb_offset_y, posz() );
1433 for( int dist = rng( 1, technique.knockback_dist ); dist > 0; dist-- ) {
1434 t.knock_back_from( kb_point );
1435 }
1436 // This technique makes the player follow into the tile the target was knocked from
1437 if( technique.knockback_follow ) {
1438 const optional_vpart_position vp0 = g->m.veh_at( pos() );
1439 vehicle *const veh0 = veh_pointer_or_null( vp0 );
1440 bool to_swimmable = g->m.has_flag( "SWIMMABLE", prev_pos );
1441 bool to_deepwater = g->m.has_flag( TFLAG_DEEP_WATER, prev_pos );
1442
1443 // Check if it's possible to move to the new tile
1444 bool move_issue =
1445 g->is_dangerous_tile( prev_pos ) || // Tile contains fire, etc
1446 ( to_swimmable && to_deepwater ) || // Dive into deep water
1447 is_mounted() ||
1448 ( veh0 != nullptr && std::abs( veh0->velocity ) > 100 ) || // Diving from moving vehicle
1449 ( veh0 != nullptr && veh0->player_in_control( g->u ) ) || // Player is driving
1451
1452 if( !move_issue ) {
1453 if( t.pos() != prev_pos ) {
1454 g->place_player( prev_pos );
1455 g->on_move_effects();
1456 }
1457 }
1458 }
1459 }
1460
1461 player *p = dynamic_cast<player *>( &t );
1462
1463 if( technique.take_weapon && !has_weapon() && p != nullptr && p->is_armed() ) {
1464 if( p->is_player() ) {
1465 add_msg_if_npc( _( "<npcname> disarms you and takes your weapon!" ) );
1466 } else {
1467 add_msg_player_or_npc( _( "You disarm %s and take their weapon!" ),
1468 _( "<npcname> disarms %s and takes their weapon!" ),
1469 p->name );
1470 }
1471 item it = p->remove_weapon();
1472 wield( it );
1473 }
1474
1475 if( technique.disarms && p != nullptr && p->is_armed() ) {
1476 g->m.add_item_or_charges( p->pos(), p->remove_weapon() );
1477 if( p->is_player() ) {
1478 add_msg_if_npc( _( "<npcname> disarms you!" ) );
1479 } else {
1480 add_msg_player_or_npc( _( "You disarm %s!" ),
1481 _( "<npcname> disarms %s!" ),
1482 p->name );
1483 }
1484 }
1485
1486 //AOE attacks, feel free to skip over this lump
1487 if( !technique.aoe.empty() ) {
1488 // Remember out moves and stamina
1489 // We don't want to consume them for every attack!
1490 const int temp_moves = moves;
1491 const int temp_stamina = get_stamina();
1492
1493 std::vector<Creature *> targets;
1494
1495 valid_aoe_technique( t, technique, targets );
1496
1497 //hit only one valid target (pierce through doesn't spread out)
1498 if( technique.aoe == "impale" ) {
1499 // TODO: what if targets is empty
1500 Creature *const v = random_entry( targets );
1501 targets.clear();
1502 targets.push_back( v );
1503 }
1504
1505 //hit the targets in the lists (all candidates if wide or burst, or just the unlucky sod if deep)
1506 int count_hit = 0;
1507 for( Creature *const c : targets ) {
1508 melee_attack( *c, false );
1509 }
1510
1511 t.add_msg_if_player( m_good, vgettext( "%d enemy hit!", "%d enemies hit!", count_hit ), count_hit );
1512 // Extra attacks are free of charge (otherwise AoE attacks would SUCK)
1513 moves = temp_moves;
1514 set_stamina( temp_stamina );
1515 }
1516
1517 //player has a very small chance, based on their intelligence, to learn a style whilst using the CQB bionic
1518 if( has_active_bionic( bio_cqb ) && !martial_arts_data->knows_selected_style() ) {
1519 /** @EFFECT_INT slightly increases chance to learn techniques when using CQB bionic */
1520 // Enhanced Memory Banks bionic doubles chance to learn martial art
1521 const int bionic_boost = has_active_bionic( bionic_id( bio_memory ) ) ? 2 : 1;
1522 if( one_in( ( 1400 - ( get_int() * 50 ) ) / bionic_boost ) ) {
1523 martial_arts_data->learn_current_style_CQB( is_player() );
1524 }
1525 }
1526}
bool valid_aoe_technique(Creature &t, const ma_technique &technique)
Check if an area-of-effect technique has valid targets.
Definition: melee.cpp:1217
bool has_weapon() const override
virtual void setpos(const tripoint &pos)=0
void knock_back_from(const tripoint &p)
Definition: creature.cpp:1885
int knockback_dist
Definition: martialarts.h:98
std::string aoe
Definition: martialarts.h:101
float armor_penetration(const Character &u, damage_type type) const
float damage_multiplier(const Character &u, damage_type type) const
bool side_switch
Definition: martialarts.h:89
float damage_bonus(const Character &u, damage_type type) const
float move_cost_multiplier(const Character &u) const
float move_cost_penalty(const Character &u) const
bool take_weapon
Definition: martialarts.h:106
bool knockback_follow
Definition: martialarts.h:102
bool powerful_knockback
Definition: martialarts.h:100
float knockback_spread
Definition: martialarts.h:99
Definition: player.h:90
bool player_in_control(const Character &p) const
Definition: vehicle.cpp:277
int velocity
Definition: vehicle.h:1918
@ TFLAG_DEEP_WATER
Definition: mapdata.h:301
static const efftype_id effect_downed("downed")
static const bionic_id bio_memory("bio_memory")
static void print_damage_info(const damage_instance &di)
Definition: melee.cpp:1349
static damage_unit & get_damage_unit(std::vector< damage_unit > &di, const damage_type dt)
Definition: melee.cpp:1337
static const efftype_id effect_stunned("stunned")
static const efftype_id effect_amigara("amigara")
void bash(const spell &sp, Creature &caster, const tripoint &target)
float damage_multiplier
Definition: damage.h:40
float res_pen
Definition: damage.h:38
vehicle * veh_pointer_or_null(const optional_vpart_position &p)

References _, Creature::add_effect(), add_msg(), Creature::add_msg_if_npc(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), damage_unit::amount, ma_technique::aoe, ma_technique::armor_penetration(), b, spell_effect::bash(), bio_cqb, bio_memory, bionic_id, c, ma_technique::damage_bonus(), damage_unit::damage_multiplier, ma_technique::damage_multiplier(), damage_instance::damage_units, ma_technique::disarms, ma_technique::down_dur, DT_BASH, effect_amigara, effect_downed, effect_stunned, time_duration::from_turns(), g, get_damage_unit(), get_int(), get_stamina(), has_active_bionic(), Creature::has_effect(), has_weapon(), is_armed(), is_mounted(), Creature::is_player(), player::is_player(), Creature::knock_back_from(), ma_technique::knockback_dist, ma_technique::knockback_follow, ma_technique::knockback_spread, m_debug, m_good, martial_arts_data, melee_attack(), move_cost(), ma_technique::move_cost_multiplier(), ma_technique::move_cost_penalty(), Creature::moves, name, one_in(), vehicle::player_in_control(), Creature::pos(), pos(), posx(), posy(), posz(), ma_technique::powerful_knockback, print_damage_info(), random_entry(), remove_weapon(), damage_unit::res_pen, rng(), set_stamina(), Creature::setpos(), ma_technique::side_switch, ma_technique::stun_dur, ma_technique::take_weapon, TFLAG_DEEP_WATER, damage_unit::type, valid_aoe_technique(), veh_pointer_or_null(), vehicle::velocity, vgettext(), and wield().

Referenced by melee_attack().

◆ perform_uninstall()

void Character::perform_uninstall ( bionic_id  bid,
int  difficulty,
int  success,
const units::energy power_lvl,
int  pl_skill 
)

Succes or failure of removal happens here.

Definition at line 2057 of file bionics.cpp.

2059{
2060 map &here = get_map();
2061 if( success > 0 ) {
2062 g->events().send<event_type::removes_cbm>( getID(), bid );
2063
2064 // until bionics can be flagged as non-removable
2065 add_msg_player_or_npc( m_neutral, _( "Your parts are jiggled back into their familiar places." ),
2066 _( "<npcname>'s parts are jiggled back into their familiar places." ) );
2067 add_msg( m_good, _( "Successfully removed %s." ), bid.obj().name );
2068 remove_bionic( bid );
2069
2070 // remove power bank provided by bionic
2071 mod_max_power_level( -power_lvl );
2072
2074 if( bid->itype().is_valid() ) {
2075 cbm = item( bid.c_str() );
2076 }
2077 cbm.faults.emplace( fault_bionic_nonsterile );
2078 here.add_item( pos(), cbm );
2079 } else {
2080 g->events().send<event_type::fails_to_remove_cbm>( getID(), bid );
2081 // for chance_of_success calculation, shift skill down to a float between ~0.4 - 30
2082 float adjusted_skill = static_cast<float>( pl_skill ) - std::min( static_cast<float>( 40 ),
2083 static_cast<float>( pl_skill ) - static_cast<float>( pl_skill ) / static_cast<float>
2084 ( 10.0 ) );
2085 bionics_uninstall_failure( difficulty, success, adjusted_skill );
2086
2087 }
2088 here.invalidate_map_cache( g->get_levz() );
2089}
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const itype_id itype_burnt_out_bionic("burnt_out_bionic")
void bionics_uninstall_failure(int difficulty, int success, float adjusted_skill)
When a player fails the surgery.
Definition: bionics.cpp:1737
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4314
@ fails_to_remove_cbm

References _, map::add_item(), add_msg(), Creature::add_msg_player_or_npc(), bionics_uninstall_failure(), string_id< T >::c_str(), fails_to_remove_cbm, fault_bionic_nonsterile, item::faults, g, get_map(), getID(), map::invalidate_map_cache(), string_id< T >::is_valid(), bionic_data::itype(), itype_burnt_out_bionic, m_good, m_neutral, mod_max_power_level(), bionic_data::name, string_id< T >::obj(), pos(), remove_bionic(), removes_cbm, and behavior::success.

Referenced by activity_handlers::operation_do_turn(), and uninstall_bionic().

◆ pick_name()

void Character::pick_name ( bool  bUseDefault = false)

Returns a random name from NAMES_*.

Definition at line 129 of file newcharacter.cpp.

130{
131 if( bUseDefault && !get_option<std::string>( "DEF_CHAR_NAME" ).empty() ) {
132 name = get_option<std::string>( "DEF_CHAR_NAME" );
133 } else {
135 }
136}
std::string generate(bool is_male)
Return a random full name given gender.
Definition: name.cpp:128

References Name::generate(), male, and name.

Referenced by avatar::randomize(), npc::randomize(), and set_description().

◆ pick_technique()

matec_id Character::pick_technique ( Creature t,
const item weap,
bool  crit,
bool  dodge_counter,
bool  block_counter 
)

Returns a random valid technique.

Definition at line 1114 of file melee.cpp.

1116{
1117
1118 const std::vector<matec_id> all = martial_arts_data->get_all_techniques( weap );
1119
1120 std::vector<matec_id> possible;
1121
1122 bool downed = t.has_effect( effect_downed );
1123 bool stunned = t.has_effect( effect_stunned );
1124 bool wall_adjacent = g->m.is_wall_adjacent( pos() );
1125
1126 // first add non-aoe tecs
1127 for( const matec_id &tec_id : all ) {
1128 const ma_technique &tec = tec_id.obj();
1129
1130 // ignore "dummy" techniques like WBLOCK_1
1131 if( tec.dummy ) {
1132 continue;
1133 }
1134
1135 // skip defensive techniques
1136 if( tec.defensive ) {
1137 continue;
1138 }
1139
1140 // skip wall adjacent techniques if not next to a wall
1141 if( tec.wall_adjacent && !wall_adjacent ) {
1142 continue;
1143 }
1144
1145 // skip dodge counter techniques
1146 if( dodge_counter != tec.dodge_counter ) {
1147 continue;
1148 }
1149
1150 // skip block counter techniques
1151 if( block_counter != tec.block_counter ) {
1152 continue;
1153 }
1154
1155 // if critical then select only from critical tecs
1156 // but allow the technique if its crit ok
1157 if( !tec.crit_ok && ( crit != tec.crit_tec ) ) {
1158 continue;
1159 }
1160
1161 // don't apply downing techniques to someone who's already downed
1162 if( downed && tec.down_dur > 0 ) {
1163 continue;
1164 }
1165
1166 // don't apply "downed only" techniques to someone who's not downed
1167 if( !downed && tec.downed_target ) {
1168 continue;
1169 }
1170
1171 // don't apply "stunned only" techniques to someone who's not stunned
1172 if( !stunned && tec.stunned_target ) {
1173 continue;
1174 }
1175
1176 // don't apply disarming techniques to someone without a weapon
1177 // TODO: these are the stat requirements for tec_disarm
1178 // dice( dex_cur + get_skill_level("unarmed"), 8) >
1179 // dice(p->dex_cur + p->get_skill_level("melee"), 10))
1180 if( tec.disarms && !t.has_weapon() ) {
1181 continue;
1182 }
1183
1184 if( ( tec.take_weapon && ( has_weapon() || !t.has_weapon() ) ) ) {
1185 continue;
1186 }
1187
1188 // Don't apply humanoid-only techniques to non-humanoids
1189 if( tec.human_target && !t.in_species( HUMAN ) ) {
1190 continue;
1191 }
1192 // if aoe, check if there are valid targets
1193 if( !tec.aoe.empty() && !valid_aoe_technique( t, tec ) ) {
1194 continue;
1195 }
1196
1197 // If we have negative weighting then roll to see if it's valid this time
1198 if( tec.weighting < 0 && !one_in( std::abs( tec.weighting ) ) ) {
1199 continue;
1200 }
1201
1202 if( tec.is_valid_character( *this ) ) {
1203 possible.push_back( tec.id );
1204
1205 //add weighted options into the list extra times, to increase their chance of being selected
1206 if( tec.weighting > 1 ) {
1207 for( int i = 1; i < tec.weighting; i++ ) {
1208 possible.push_back( tec.id );
1209 }
1210 }
1211 }
1212 }
1213
1214 return random_entry( possible, tec_none );
1215}
virtual bool in_species(const species_id &) const
Definition: creature.cpp:965
virtual bool has_weapon() const =0
bool stunned_target
Definition: martialarts.h:117
bool defensive
Definition: martialarts.h:88
bool human_target
Definition: martialarts.h:119
bool block_counter
Definition: martialarts.h:108
bool wall_adjacent
Definition: martialarts.h:118
bool dodge_counter
Definition: martialarts.h:107
bool downed_target
Definition: martialarts.h:116
static const species_id HUMAN("HUMAN")
const std::array< type, 4 > all
For the purposes of iteration.
Definition: om_direction.h:26

References om_direction::all, ma_technique::aoe, ma_technique::block_counter, ma_technique::crit_ok, ma_technique::crit_tec, ma_technique::defensive, ma_technique::disarms, ma_technique::dodge_counter, ma_technique::down_dur, ma_technique::downed_target, ma_technique::dummy, effect_downed, effect_stunned, g, Creature::has_effect(), Creature::has_weapon(), has_weapon(), HUMAN, ma_technique::human_target, ma_technique::id, Creature::in_species(), ma_technique::is_valid_character(), martial_arts_data, one_in(), pos(), random_entry(), ma_technique::stunned_target, ma_technique::take_weapon, tec_none, valid_aoe_technique(), ma_technique::wall_adjacent, and ma_technique::weighting.

Referenced by block_hit(), melee_attack(), and player::on_dodge().

◆ place_corpse() [1/2]

void Character::place_corpse ( )

Definition at line 10136 of file character.cpp.

10137{
10138 //If the character/NPC is on a distant mission, don't drop their their gear when they die since they still have a local pos
10139 if( !death_drops ) {
10140 return;
10141 }
10142 std::vector<item *> tmp = inv_dump();
10144 map &here = get_map();
10145 for( auto itm : tmp ) {
10146 here.add_item_or_charges( pos(), *itm );
10147 }
10148 for( const bionic &bio : *my_bionics ) {
10149 if( bio.info().itype().is_valid() ) {
10150 item cbm( bio.id.str(), calendar::turn );
10151 cbm.faults.emplace( fault_bionic_nonsterile );
10152 body.components.push_back( cbm );
10153 }
10154 }
10155
10156 // Restore amount of installed pseudo-modules of Power Storage Units
10157 std::pair<int, int> storage_modules = amount_of_storage_bionics();
10158 for( int i = 0; i < storage_modules.first; ++i ) {
10160 cbm.faults.emplace( fault_bionic_nonsterile );
10161 body.components.push_back( cbm );
10162 }
10163 for( int i = 0; i < storage_modules.second; ++i ) {
10165 cbm.faults.emplace( fault_bionic_nonsterile );
10166 body.components.push_back( cbm );
10167 }
10168 here.add_item_or_charges( pos(), body );
10169}
static const itype_id itype_power_storage("bio_power_storage")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const itype_id itype_power_storage_mkII("bio_power_storage_mkII")
bool death_drops
Definition: character.h:225
std::pair< int, int > amount_of_storage_bionics() const
Returns amount of Storage CBMs in the corpse.
Definition: bionics.cpp:2628
std::map< bodypart_str_id, bodypart > body
this is the actual body of the creature
Definition: creature.h:493
static item make_corpse(const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
Make a corpse of the given monster type.
Definition: item.cpp:506

References map::add_item_or_charges(), amount_of_storage_bionics(), Creature::body, death_drops, fault_bionic_nonsterile, item::faults, get_map(), inv_dump(), itype_power_storage, itype_power_storage_mkII, item::make_corpse(), my_bionics, name, string_id< mtype >::NULL_ID(), pos(), and calendar::turn.

Referenced by npc::die(), game::handle_action(), and game::is_game_over().

◆ place_corpse() [2/2]

void Character::place_corpse ( const tripoint_abs_omt om_target)

Definition at line 10171 of file character.cpp.

10172{
10173 tinymap bay;
10174 bay.load( project_to<coords::sm>( om_target ), false );
10175 point fin{ rng( 1, SEEX * 2 - 2 ), rng( 1, SEEX * 2 - 2 ) };
10176 // This makes no sense at all. It may find a random tile without furniture, but
10177 // if the first try to find one fails, it will go through all tiles of the map
10178 // and essentially select the last one that has no furniture.
10179 // Q: Why check for furniture? (Check for passable or can-place-items seems more useful.)
10180 // Q: Why not grep a random point out of all the possible points (e.g. via random_entry)?
10181 // Q: Why use furn_str_id instead of f_null?
10182 // TODO: fix it, see above.
10183 if( bay.furn( fin ) != furn_str_id( "f_null" ) ) {
10184 for( const tripoint &p : bay.points_on_zlevel() ) {
10185 if( bay.furn( p ) == furn_str_id( "f_null" ) ) {
10186 fin.x = p.x;
10187 fin.y = p.y;
10188 }
10189 }
10190 }
10191
10192 std::vector<item *> tmp = inv_dump();
10194 for( auto itm : tmp ) {
10195 bay.add_item_or_charges( fin, *itm );
10196 }
10197 for( const bionic &bio : *my_bionics ) {
10198 if( bio.info().itype().is_valid() ) {
10199 body.put_in( item( bio.info().itype(), calendar::turn ) );
10200 }
10201 }
10202
10203 // Restore amount of installed pseudo-modules of Power Storage Units
10204 std::pair<int, int> storage_modules = amount_of_storage_bionics();
10205 for( int i = 0; i < storage_modules.first; ++i ) {
10206 body.put_in( item( "bio_power_storage" ) );
10207 }
10208 for( int i = 0; i < storage_modules.second; ++i ) {
10209 body.put_in( item( "bio_power_storage_mkII" ) );
10210 }
10211 bay.add_item_or_charges( fin, body );
10212}
tripoint_range< tripoint > points_on_zlevel() const
Yields a range of all points that are contained in the map and have the z-level of this map (abs_sub)...
Definition: map.cpp:8580
void load(const tripoint &w, bool update_vehicles)
Load submaps into grid.
Definition: map.cpp:6591
Definition: map.h:2087

References map::add_item_or_charges(), amount_of_storage_bionics(), Creature::body, map::furn(), inv_dump(), map::load(), item::make_corpse(), my_bionics, name, string_id< mtype >::NULL_ID(), map::points_on_zlevel(), rng(), SEEX, and calendar::turn.

◆ pos()

const tripoint & Character::pos ( ) const
overridevirtual

Implements Creature.

Definition at line 714 of file character.cpp.

715{
716 return position;
717}

References position.

Referenced by absorb_hit(), iuse::acidbomb_act(), activate_bionic(), npc::activate_item(), activate_mutation(), enchantment::activate_passive(), activity_on_turn_move_loot(), map::add_field(), add_known_trap(), inventory_selector::add_nearby_items(), npc::address_player(), adjacent_tile(), npc::alt_attack(), map::apply_character_light(), apply_persistent_morale(), iuse::artifact(), npc::assess_danger(), assign_activity(), activity_handlers::atm_do_turn(), Creature::auto_find_hostile_target(), game::autopilot_vehicles(), npc::avoid_friendly_fire(), player::avoid_trap(), base_comfort_value(), iuse::bell(), best_nearby_lifting_assist(), mattack::bio_op_disarm(), blossoms(), iuse::boltcutters(), burn_fuel(), iuse::burrow(), game::butcher(), activity_handlers::butcher_finish(), butchery_drops_harvest(), butchery_quarter(), set_transformed_iuse::bypass(), iuse::cable_attach(), calc_needs_rates(), calculate_aim_cap(), calculate_dispersion(), iuse::call_of_tindalos(), iuse::camera(), player::can_continue_craft(), can_examine_at(), can_hear(), can_mount(), npc::can_move_to(), player::can_sleep(), iuse_transform::can_use(), firestarter_actor::can_use(), iuse::capture_monster_act(), iexamine::cardreader_foodplace(), enchantment::cast_enchantment_spell(), iexamine::chainfence(), debug_menu::character_edit_menu(), game::chat(), check_art_charge_req(), player::check_eligible_containers_for_crafting(), check_mount_will_move(), npc::check_or_use_weapon_cbm(), check_outbounds_activity(), iuse::chop_tree(), avatar::clear_memorized_tile(), doors::close_door(), game_menus::inv::compare(), complete_construction(), veh_interact::complete_vehicle(), consider_butchery(), consume_charges(), consume_effects(), player::consume_items(), player::consume_med(), consume_remote_fuel(), player::consume_tools(), game::control_vehicle(), cough(), npc::could_move_onto(), player::craft_consume_tools(), crafting_inventory(), craft_command::create_in_progress_craft(), game::create_starting_npcs(), map::creature_in_field(), game::critter_at(), iuse::crowbar(), iexamine::curtains(), iuse::cut_log_into_planks(), salvage_actor::cut_up(), deactivate_bionic(), deal_damage(), debug_menu::debug(), defer_move(), item_location::impl::item_on_map::describe(), item_location::impl::item_on_vehicle::describe(), vehicle::deserialize(), trap::detect_trap(), npc::die(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), player::disarm(), player::disassemble_all(), character_display::disp_info(), game::disp_NPCs(), game::display_scent(), npc::dispose_item(), npc::do_npc_read(), npc::do_pulp(), avatar::do_read(), npc::do_reload(), game::do_turn(), drop_activity_actor::do_turn(), stash_activity_actor::do_turn(), move_items_activity_actor::do_turn(), pickup_activity_actor::do_turn(), iexamine::door_peephole(), game::draw(), draw_bionics_titlebar(), draw_cone_aoe_curses(), draw_env_compact(), draw_health_classic(), anonymous_namespace{animation.cpp}::draw_hit_player_curses(), game::draw_look_around_cursor(), draw_speed_tab(), game::draw_ter(), target_ui::draw_terrain_overlay(), draw_throw_aim(), draw_time_classic(), game::draw_trail_to_square(), draw_veh_compact(), draw_veh_padding(), game::drop(), drop(), drop_invalid_inventory(), npc::drop_items(), talk_function::drop_weapon(), player::eat(), avatar_action::eat_here(), eff_fun_fungus(), eff_fun_hallu(), iuse::einktabletpc(), iexamine::elevator(), emit_radio_signal(), explosion_handler::emp_blast(), npc::enough_time_to_reload(), env_surgery_bonus(), game::examine(), craft_command::execute(), npc::execute_action(), extract_or_wreck_cbms(), npc::faction_display(), iuse::fill_pit(), find_ammo(), find_auto_consume(), find_best_bench(), npc::find_corpse_to_pulp(), npc::find_dangerous_explosives(), npc::find_item(), activity_handlers::find_mount_do_turn(), game::find_nearby_items(), game::find_or_make_stairs(), find_remote_fuel(), player::fine_detail_vision_mod(), hacking_activity_actor::finish(), npc::finish_read(), fire(), player::fire_gun(), iuse::fishing_rod(), game::fling_creature(), floor_bedding_warmth(), floor_item_warmth(), floor_warmth(), iexamine::flower_marloss(), iexamine::flower_poppy(), activity_handlers::forage_finish(), forced_dismount(), fungal_effects::fungalize(), iuse::fungicide(), mattack::fungus_sprout(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), iexamine::gaspump(), iuse::geiger(), generic_multi_activity_check_requirement(), generic_multi_activity_handler(), generic_multi_activity_locations(), get_avatar(), avatar::get_book_reader(), player::get_crafting_helpers(), game::get_dangerous_tile(), activatable_inventory_preset::get_denial(), get_dodge(), player::get_eligible_containers_for_crafting(), get_heat_radiation(), get_hostile_creatures(), get_item_location(), avatar::get_memorized_tile(), get_next_auto_move_direction(), overmap_ui::get_overmap_path_to(), npc::get_path_avoid(), get_patient(), get_temp(), game::get_veh_dir_indicator_location(), get_visible_creatures(), player::get_weapon_dispersion(), talk_function::give_all_aid(), npc::go_to_omt_destination(), npc::good_escape_direction(), grab(), mattack::grab_drag(), game::grabbed_furn_move(), game::grabbed_veh_move(), npc::guard_current_pos(), iuse::gun_repair(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hacksaw(), activity_handlers::hacksaw_finish(), iuse::hammer(), handbrake(), game::handle_action(), target_ui::handle_cursor_movement(), handle_harvest(), handle_melee_wear(), vehicle::handle_potential_theft(), npc::handle_sound(), vehicle::handle_trap(), player::hardcoded_effects(), has_alarm_clock(), has_fire(), has_neighbor(), has_watch(), haul(), npc::heal_player(), npc::heal_self(), heat_emission(), iuse::honeycomb(), i_add_or_drop(), i_rem(), i_rem_keep_contents(), player::impact(), in_climate_control(), npc_trading::init_buying(), iexamine::intercom(), game::inventory_item_menu(), invoke_item(), avatar::invoke_item(), npc::is_active(), enchantment::is_active(), place_trap_actor::is_allowed(), is_deaf(), is_driving(), monster::is_fleeing(), game::is_game_over(), game::is_in_viewport(), is_snuggling(), is_solid_neighbor(), ma_requirements::is_valid_character(), is_visible_in_range(), iuse::jackhammer(), player::knock_back_to(), game::knockback(), knows_trap(), firestarter_actor::light_mod(), game::list_items(), game::list_monsters(), monster::load(), vehicle_prototype::load(), game::load(), avatar::load_map_memory(), aim_activity_actor::load_RAS_weapon(), activity_handlers::lockpicking_finish(), activity_handlers::longsalvage_finish(), game::look_around(), npc::look_for_player(), loot(), iuse::lumber(), make_gun_sound_effect(), activity_handlers::make_zlave_finish(), iuse::makemound(), item_action_generator::map_actions_to_items(), marloss_common(), melee_attack(), melee_special_effects(), avatar::memorize_symbol(), npc::method_of_attack(), mill_activate(), target_handler::mode_turrets(), modify_morale(), game::mon_info_update(), game::monmove(), iuse::mop(), npc::move(), avatar_action::move(), npc::move_away_from(), npc::move_to(), npc::move_to_next(), firestarter_actor::moves_cost_by_fuel(), game::moving_vehicle_dismount(), npc::mug_player(), multicooker_hallu(), mutation_effect(), npc::mutiny(), iuse::mycus(), inventory_selector::naturalize_category(), nearby(), iuse::note_bionics(), npc::npc_dismount(), game::npc_menu(), mattack::nurse_assist(), mattack::nurse_check_up(), mattack::nurse_operate(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), player::on_dodge(), npc::on_load(), item::on_pickup(), item::on_takeoff(), item::on_wear(), open(), activity_handlers::operation_do_turn(), activity_handlers::operation_finish(), operator_present(), game::overmap_npc_move(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::oxytorch_finish(), passive_power_gen(), player::pause(), iexamine::pay_gas(), game::peek(), perform_technique(), perform_uninstall(), perform_zone_activity_turn(), game::phasing_move(), debug_menu::pick_character(), pick_plant(), pick_technique(), npc::pick_up_item(), iuse::pickaxe(), game::pickup_feet(), iexamine::pit_covered(), place_and_add_as_known(), place_corpse(), npc::place_on_map(), game::place_player(), start_location::place_player(), game::place_player_overmap(), iuse::play_music(), vehicle::player_in_control(), map::player_in_field(), player_on_couch(), pldrive(), avatar_action::plthrow(), item_location::impl::item_on_person::position(), firestarter_actor::prep_firestarter_use(), npc::pretend_fire(), print_aim(), npc::print_info(), print_items(), game::process_artifact(), process_bionic(), player::process_effects_internal(), player::process_items(), sounds::process_sound_markers(), player::process_turn(), activity_handlers::pry_nails_finish(), iexamine::quern_examine(), query_consume_ownership(), plot_options::query_seed(), avatar_action::ramp_move(), mattack::ranged_pull(), player::reach_attack(), npc::reach_omt_destination(), read(), player::recalc_speed_bonus(), recoil_vehicle(), activity_handlers::reload_finish(), vehicle::remote_controlled(), render_wind(), veh_utils::repair_part(), requirements_map(), firestarter_actor::resolve_firestarter_use(), iuse::robotcontrol(), iuse::robotcontrol_can_target(), rod_fish(), rooted(), rooted_message(), route_adjacent(), target_ui::run(), run_cost(), avatar::save_map_memory(), npc::say(), player::search_surroundings(), npc::see_item_say_smth(), sees(), sees_with_infrared(), vehicle::serialize(), conditional_t< T >::set_is_driving(), set_item_inventory(), avatar::set_movement_mode(), conditional_t< T >::set_npc_role_nearby(), talk_effect_fun_t::set_u_buy_monster(), monster::setpos(), npc::setpos(), activity_handlers::shear_finish(), npc::shift(), shout(), iexamine::shrub_marloss(), sight_range(), sinkhole_safety_roll(), player::sleep_spot(), smash(), smoker_activate(), iexamine::smoker_options(), player::sort_armor(), spawn_animal(), spawn_spores(), activity_handlers::spellcasting_finish(), spores(), standard_npc::standard_npc(), autodrive_activity_actor::start(), activity_handlers::start_fire_do_turn(), game::start_game(), monster::store(), npc::stow_item(), suffer_from_bad_bionics(), suffer_from_other_mutations(), suffer_from_radiation(), suffer_from_schizophrenia(), suffer_in_sunlight(), suffer_while_underwater(), game::swap_critters(), avatar_action::swim(), symbol_color(), player::takeoff(), iuse::talking_doll(), iuse::tazer(), player::throw_item(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), activity_handlers::travel_do_turn(), npc::travel_overmap(), iexamine::tree_hickory(), iexamine::tree_maple_tapped(), iexamine::tree_marloss(), explosion_iuse::trigger_explosion(), try_consume(), try_fuel_fire(), game::try_get_left_click_action(), game::try_get_right_click_action(), try_reject_mutagen(), salvage_actor::try_to_cut_up(), player::try_to_sleep(), iuse::unfold_generic(), uninstall_bionic(), player::unload(), update_bodytemp(), update_needs(), npc::update_path(), game::update_stair_monsters(), editmap::update_view_with_help(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), delayed_transform_iuse::use(), set_transform_iuse::use(), set_transformed_iuse::use(), place_monster_iuse::use(), place_npc_iuse::use(), pick_lock_actor::use(), deploy_furn_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), musical_instrument_actor::use(), holster_actor::use(), heal_actor::use(), place_trap_actor::use(), emit_actor::use(), mutagen_iv_actor::use(), deploy_tent_actor::use(), unpack_actor::use(), use_charges(), use_fire(), valid_aoe_technique(), game::validate_camps(), game::vertical_move(), activity_handlers::vibe_do_turn(), vomit(), iuse::vortex(), wait(), game::walk_move(), npc::warn_about(), player::wear(), iuse::weather_tool(), npc::wield(), player::wield_contents(), npc::wont_hit_friend(), npc::worker_downtime(), and game::zones_manager().

◆ position_to_wear_new_item()

std::list< item >::iterator Character::position_to_wear_new_item ( const item new_item)
protected

Return the position in the worn list where new_item would be put by default.

Definition at line 3945 of file character.cpp.

3946{
3947 // By default we put this item on after the last item on the same or any
3948 // lower layer.
3949 return std::find_if(
3950 worn.rbegin(), worn.rend(),
3951 [&]( const item & w ) {
3952 return w.get_layer() <= new_item.get_layer();
3953 }
3954 ).base();
3955}

References worn.

Referenced by item_encumb(), and wear_item().

◆ posx()

◆ posy()

◆ posz()

◆ pour_into() [1/2]

bool Character::pour_into ( item container,
item liquid 
)

Try to pour the given liquid into the given container/vehicle.

The transferred charges are removed from the liquid item. Check the charges of afterwards to see if anything has been transferred at all. The functions do not consume any move points.

Returns
Whether anything has been moved at all. false indicates the transfer is not possible at all. true indicates at least some of the liquid has been moved.

Definition at line 6459 of file character.cpp.

6460{
6461 std::string err;
6462 const int amount = container.get_remaining_capacity_for_liquid( liquid, *this, &err );
6463
6464 if( !err.empty() ) {
6465 add_msg_if_player( m_bad, err );
6466 return false;
6467 }
6468
6469 add_msg_if_player( _( "You pour %1$s into the %2$s." ), liquid.tname(), container.tname() );
6470
6471 container.fill_with( liquid, amount );
6472 inv.unsort();
6473
6474 if( liquid.charges > 0 ) {
6475 add_msg_if_player( _( "There's some left over!" ) );
6476 }
6477
6478 return true;
6479}
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8400
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8262

References _, Creature::add_msg_if_player(), item::charges, item::fill_with(), item::get_remaining_capacity_for_liquid(), inv, m_bad, item::tname(), and inventory::unsort().

Referenced by activity_handlers::fill_liquid_do_turn().

◆ pour_into() [2/2]

bool Character::pour_into ( vehicle veh,
item liquid 
)

Definition at line 6481 of file character.cpp.

6482{
6483 auto sel = [&]( const vehicle_part & pt ) {
6484 return pt.is_tank() && pt.can_reload( liquid );
6485 };
6486
6487 auto stack = units::legacy_volume_factor / liquid.type->stack_size;
6488 auto title = string_format( _( "Select target tank for <color_%s>%.1fL %s</color>" ),
6489 get_all_colors().get_name( liquid.color() ),
6490 round_up( to_liter( liquid.charges * stack ), 1 ),
6491 liquid.tname() );
6492
6493 auto &tank = veh_interact::select_part( veh, sel, title );
6494 if( !tank ) {
6495 return false;
6496 }
6497
6498 tank.fill_with( liquid );
6499
6500 //~ $1 - vehicle name, $2 - part name, $3 - liquid type
6501 add_msg_if_player( _( "You refill the %1$s's %2$s with %3$s." ),
6502 veh.name, tank.name(), liquid.type_name() );
6503
6504 if( liquid.charges > 0 ) {
6505 add_msg_if_player( _( "There's some left over!" ) );
6506 }
6507 return true;
6508}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
std::string get_name() const override
Definition: character.cpp:6110
nc_color color() const
Returns the default color of the item (e.g.
Definition: item.cpp:4790
static vehicle_part & select_part(const vehicle &veh, const part_selector &sel, const std::string &title=std::string())
Prompt for a part matching the selector function.
std::string name
Definition: vehicle.h:1849
color_manager & get_all_colors()
Definition: color.cpp:45
std::string title(holiday current_holiday)
Definition: path_info.cpp:330
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
Structure, describing vehicle part (i.e., wheel, seat)
Definition: vehicle.h:185

References _, Creature::add_msg_if_player(), item::charges, item::color(), get_all_colors(), get_name(), units::legacy_volume_factor, vehicle::name, round_up(), veh_interact::select_part(), itype::stack_size, string_format(), PATH_INFO::title(), item::tname(), units::to_liter(), item::type, and item::type_name().

◆ power_rating()

float Character::power_rating ( ) const
overridevirtual

Returns an approximation of the creature's strength.

Implements Creature.

Definition at line 9979 of file character.cpp.

9980{
9981 int dmg = std::max( { weapon.damage_melee( DT_BASH ),
9984 } );
9985
9986 int ret = 2;
9987 // Small guns can be easily hidden from view
9988 if( weapon.volume() <= 250_ml ) {
9989 ret = 2;
9990 } else if( weapon.is_gun() ) {
9991 ret = 4;
9992 } else if( dmg > 12 ) {
9993 ret = 3; // Melee weapon or weapon-y tool
9994 }
9995 if( get_size() == MS_HUGE ) {
9996 ret += 1;
9997 }
9998 if( is_wearing_power_armor( nullptr ) ) {
9999 ret = 5; // No mercy!
10000 }
10001 return ret;
10002}

References item::damage_melee(), DT_BASH, DT_CUT, DT_STAB, get_size(), item::is_gun(), is_wearing_power_armor(), MS_HUGE, cata::hash64_detail::ret, item::volume(), and weapon.

◆ print_health()

void Character::print_health ( ) const

Definition at line 4211 of file character.cpp.

4212{
4213 if( !is_player() ) {
4214 return;
4215 }
4216 int current_health = get_healthy();
4217 if( has_trait( trait_SELFAWARE ) ) {
4218 add_msg_if_player( _( "Your current health value is %d." ), current_health );
4219 }
4220
4221 static const std::map<int, std::string> msg_categories = {
4222 { -100, "health_horrible" },
4223 { -50, "health_very_bad" },
4224 { -10, "health_bad" },
4225 { 10, "" },
4226 { 50, "health_good" },
4227 { 100, "health_very_good" },
4228 { INT_MAX, "health_great" }
4229 };
4230
4231 auto iter = msg_categories.lower_bound( current_health );
4232 if( iter != msg_categories.end() && !iter->second.empty() ) {
4233 const translation msg = SNIPPET.random_from_category( iter->second ).value_or( translation() );
4234 add_msg_if_player( current_health > 0 ? m_good : m_bad, "%s", msg );
4235 }
4236}

References _, Creature::add_msg_if_player(), get_healthy(), has_trait(), Creature::is_player(), m_bad, m_good, snippet_library::random_from_category(), SNIPPET, and trait_SELFAWARE.

Referenced by activate_mutation(), and avatar::wake_up().

◆ print_info()

int Character::print_info ( const catacurses::window w,
int  vStart,
int  vLines,
int  column 
) const
overridevirtual

Write information about this creature.

Parameters
wthe window to print the text into.
vStartvertical start to print, that means the first line to print.
vLinesnumber of lines to print at most (printing less is fine).
columnhorizontal start to print (column), horizontal end is one character before the right border of the window (to keep the border).
Returns
The line just behind the last printed line, that means multiple calls to this can be stacked, the return value is acceptable as vStart for the next call without creating empty lines or overwriting lines.

Implements Creature.

Reimplemented in npc.

Definition at line 10345 of file character.cpp.

10346{
10347 mvwprintw( w, point( column, vStart++ ), _( "You (%s)" ), name );
10348 return vStart;
10349}
void mvwprintw(const window &win, const point &p, const std::string &text)

References _, catacurses::mvwprintw(), and name.

◆ process_bionic()

void Character::process_bionic ( int  b)

Handles bionic effects over time of the entered bionic.

Definition at line 1528 of file bionics.cpp.

1529{
1530 bionic &bio = ( *my_bionics )[b];
1531 if( ( !bio.id->fuel_opts.empty() || bio.id->is_remote_fueled ) && bio.is_auto_start_on() ) {
1532 const float start_threshold = bio.get_auto_start_thresh();
1533 std::vector<itype_id> fuel_available = get_fuel_available( bio.id );
1534 if( bio.id->is_remote_fueled ) {
1535 const itype_id rem_fuel = find_remote_fuel();
1536 const std::string rem_amount = get_value( "rem_" + rem_fuel.str() );
1537 int rem_fuel_stock = 0;
1538 if( !rem_amount.empty() ) {
1539 rem_fuel_stock = std::stoi( rem_amount );
1540 }
1541 if( !rem_fuel.is_empty() && ( rem_fuel_stock > 0 ||
1542 item( rem_fuel ).has_flag( flag_PERPETUAL ) ) ) {
1543 fuel_available.emplace_back( rem_fuel );
1544 }
1545 }
1546 if( !fuel_available.empty() && get_power_level() <= start_threshold * get_max_power_level() ) {
1547 g->u.activate_bionic( b );
1548 } else if( get_power_level() <= start_threshold * get_max_power_level() &&
1549 calendar::once_every( 1_hours ) ) {
1550 add_msg_player_or_npc( m_bad, _( "Your %s does not have enough fuel to use Auto Start." ),
1551 _( "<npcname>'s %s does not have enough fuel to use Auto Start." ),
1552 bio.info().name );
1553 }
1554 }
1555
1556 // Only powered bionics should be processed
1557 if( !bio.powered ) {
1559 return;
1560 }
1561
1562 // These might be affected by environmental conditions, status effects, faulty bionics, etc.
1563 int discharge_factor = 1;
1564 int discharge_rate = 1;
1565
1566 if( bio.charge_timer > 0 ) {
1567 bio.charge_timer -= discharge_rate;
1568 } else {
1569 if( bio.info().charge_time > 0 ) {
1570 if( bio.info().has_flag( STATIC( flag_str_id( "BIONIC_POWER_SOURCE" ) ) ) ) {
1571 // Convert fuel to bionic power
1572 burn_fuel( b );
1573 // Reset timer
1574 bio.charge_timer = bio.info().charge_time;
1575 } else {
1576 // Try to recharge our bionic if it is made for it
1577 units::energy cost = 0_J;
1578 bool recharged = attempt_recharge( *this, bio, cost, discharge_factor, discharge_rate );
1579 if( !recharged ) {
1580 // No power to recharge, so deactivate
1581 bio.powered = false;
1582 add_msg_if_player( m_neutral, _( "Your %s powers down." ), bio.info().name );
1583 // This purposely bypasses the deactivation cost
1584 deactivate_bionic( b, true );
1585 return;
1586 }
1587 if( cost > 0_J ) {
1588 mod_power_level( -cost );
1589 }
1590 }
1591 }
1592 }
1593
1594 // Bionic effects on every turn they are active go here.
1595 if( bio.id == bio_remote ) {
1596 if( g->remoteveh() == nullptr && get_value( "remote_controlling" ).empty() ) {
1597 bio.powered = false;
1598 add_msg_if_player( m_warning, _( "Your %s has lost connection and is turning off." ),
1599 bio.info().name );
1600 }
1601 } else if( bio.id == bio_hydraulics ) {
1602 // Sound of hissing hydraulic muscle! (not quite as loud as a car horn)
1603 sounds::sound( pos(), 19, sounds::sound_t::activity, _( "HISISSS!" ), false, "bionic",
1604 static_cast<std::string>( bio_hydraulics ) );
1605 } else if( bio.id == bio_nanobots ) {
1606 // Total hack, prevents charge_timer reaching 0 thus preventing power draw.
1607 // Ideally there would be a value that directly impacts whether a bionic draws power when idle.
1608 bio.charge_timer = 2;
1609 // The above hack means there's no check for whether the bionic actually has power to run.
1610 if( get_power_level() < bio.info().power_over_time ) {
1611 bio.powered = false;
1612 add_msg_if_player( m_warning, _( "Your %s shut down due to lack of power." ), bio.info().name );
1614 return;
1615 } else if( get_stored_kcal() < 0.85f * max_stored_kcal() ) {
1616 bio.powered = false;
1617 add_msg_if_player( m_warning, _( "Your %s shut down to conserve calories." ), bio.info().name );
1619 return;
1620 }
1621 if( calendar::once_every( 15_turns ) ) {
1622 std::vector<bodypart_id> bleeding_bp_parts;
1623 for( const bodypart_id &bp : get_all_body_parts() ) {
1624 if( has_effect( effect_bleed, bp.id() ) ) {
1625 bleeding_bp_parts.push_back( bp );
1626 }
1627 }
1628 if( !bleeding_bp_parts.empty() ) {
1629 const bodypart_id part_to_staunch = bleeding_bp_parts[ rng( 0, bleeding_bp_parts.size() - 1 ) ];
1630 effect &e = get_effect( effect_bleed, part_to_staunch->token );
1631 if( e.get_intensity() > 1 ) {
1632 e.mod_intensity( -1, false );
1633 } else {
1634 remove_effect( effect_bleed, part_to_staunch->token );
1635 }
1636 }
1637 if( rng( 0, 2 ) == 2 ) {
1638 std::vector<bodypart_id> damaged_hp_parts;
1639 for( const std::pair<const bodypart_str_id, bodypart> &part : get_body() ) {
1640 const int hp_cur = part.second.get_hp_cur();
1641 if( hp_cur > 0 && hp_cur < part.second.get_hp_max() ) {
1642 damaged_hp_parts.push_back( part.first.id() );
1643 }
1644 }
1645 if( get_stored_kcal() >= 5 && !damaged_hp_parts.empty() ) {
1646 const bodypart_id part_to_heal = damaged_hp_parts[ rng( 0, damaged_hp_parts.size() - 1 ) ];
1647 heal( part_to_heal, 1 );
1649 mod_stored_kcal( -5 );
1650 }
1651 }
1652 }
1653 } else if( bio.id == bio_painkiller ) {
1654 const int pkill = get_painkiller();
1655 const int pain = get_pain();
1656 int max_pkill = std::min( 150, pain );
1657 if( pkill < max_pkill ) {
1658 mod_painkiller( 1 );
1659 mod_power_level( -2_kJ );
1660 }
1661
1662 // Only dull pain so extreme that we can't pkill it safely
1663 if( pkill >= 150 && pain > pkill && get_stim() > -150 ) {
1664 mod_pain( -1 );
1665 // Negative side effect: negative stim
1666 mod_stim( -1 );
1667 mod_power_level( -2_kJ );
1668 }
1669 } else if( bio.id == bio_gills ) {
1670 if( has_effect( effect_asthma ) ) {
1672 _( "You feel your throat open up and air filling your lungs!" ) );
1674 }
1675 } else if( bio.id == bio_evap ) {
1676 // Aero-Evaporator provides water at 60 watts with 2 L / kWh efficiency
1677 // which is 10 mL per 5 minutes. Humidity can modify the amount gained.
1678 if( calendar::once_every( 5_minutes ) ) {
1679 const w_point &weatherPoint = get_weather().get_precise();
1680 int humidity = get_local_humidity( weatherPoint.humidity, get_weather().weather_id,
1681 g->is_sheltered( g->u.pos() ) );
1682 // in thirst units = 5 mL water
1683 int water_available = std::lround( humidity * 3.0 / 100.0 );
1684 // At 50% relative humidity or more, the player will draw 10 mL
1685 // At 16% relative humidity or less, the bionic will give up
1686 if( water_available == 0 ) {
1688 _( "There is not enough humidity in the air for your %s to function." ),
1689 bio.info().name );
1691 } else if( water_available == 1 ) {
1693 _( "Your %s issues a low humidity warning. Efficiency is reduced." ),
1694 bio.info().name );
1695 }
1696
1697 mod_thirst( -water_available );
1698 }
1699
1702 _( "You are properly hydrated. Your %s chirps happily." ),
1703 bio.info().name );
1705 }
1706 } else if( bio.id == bio_ads ) {
1707 if( bio.charge_timer < 2 ) {
1708 bio.charge_timer = 2;
1709 }
1710 if( bio.energy_stored < 150_kJ ) {
1711 // Max recharge rate is influenced by whether you've been hit or not.
1712 // See character.cpp for how charge_timer keeps track of that for this bionic.
1713 units::energy max_rate = 10_kJ;
1714 if( bio.charge_timer > 2 ) {
1715 max_rate /= 2;
1716 }
1717 units::energy ads_recharge = std::min( max_rate, 150_kJ - bio.energy_stored );
1718 if( ads_recharge < get_power_level() ) {
1719 mod_power_level( - ads_recharge );
1720 bio.energy_stored += ads_recharge;
1721 } else if( get_power_level() != 0_kJ ) {
1724 }
1725 if( bio.energy_stored == 150_kJ ) {
1726 add_msg_if_player( m_good, _( "Your %s quietens to a satisfied thrum." ), bio.info().name );
1727 }
1728 } else if( bio.energy_stored > 150_kJ ) {
1729 bio.energy_stored = 150_kJ;
1730 }
1731 } else if( bio.id == afs_bio_dopamine_stimulators ) {
1732 // Aftershock
1733 add_morale( MORALE_FEELING_GOOD, 20, 20, 30_minutes, 20_minutes, true );
1734 }
1735}
static const efftype_id effect_bleed("bleed")
static bool attempt_recharge(Character &p, bionic &bio, units::energy &amount, int factor=1, int rate=1)
Definition: bionics.cpp:1508
static const efftype_id effect_asthma("asthma")
static const bionic_id afs_bio_dopamine_stimulators("afs_bio_dopamine_stimulators")
static const bionic_id bio_nanobots("bio_nanobots")
static const bionic_id bio_gills("bio_gills")
void passive_power_gen(int b)
Passively produce power from PERPETUAL fuel.
Definition: bionics.cpp:1313
void mod_painkiller(int npkill)
Modifies intensity of painkillers
Definition: character.cpp:9797
int mod_intensity(int mod, bool alert=false)
Modify intensity of effect capped by range [1..max_intensity].
Definition: effect.cpp:886
const morale_type MORALE_FEELING_GOOD("morale_feeling_good")
units::energy power_over_time
Power cost over time, does nothing without a non-zero charge_time.
Definition: bionics.h:41
float get_auto_start_thresh() const
Definition: bionics.cpp:2758
bool is_auto_start_on() const
Definition: bionics.cpp:2763

References _, sounds::activity, add_morale(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), afs_bio_dopamine_stimulators, attempt_recharge(), b, bio_ads, bio_evap, bio_gills, bio_hydraulics, bio_nanobots, bio_painkiller, bio_remote, burn_fuel(), bionic_data::charge_time, bionic::charge_timer, deactivate_bionic(), effect_asthma, effect_bleed, bionic::energy_stored, find_remote_fuel(), flag_PERPETUAL(), bionic_data::fuel_opts, g, Creature::get_all_body_parts(), bionic::get_auto_start_thresh(), Creature::get_body(), Creature::get_effect(), get_fuel_available(), effect::get_intensity(), get_local_humidity(), get_max_power_level(), Creature::get_pain(), get_painkiller(), get_power_level(), weather_manager::get_precise(), get_stim(), get_stored_kcal(), get_thirst(), Creature::get_value(), get_weather(), Creature::has_effect(), bionic_data::has_flag(), Creature::has_flag(), heal(), w_point::humidity, hydrated, bionic::id, string_id< T >::id(), bionic::info(), bionic::is_auto_start_on(), string_id< T >::is_empty(), bionic_data::is_remote_fueled, m_bad, m_good, m_mixed, m_neutral, m_warning, max_stored_kcal(), effect::mod_intensity(), Creature::mod_pain(), mod_painkiller(), mod_power_level(), mod_stim(), mod_stored_kcal(), mod_thirst(), MORALE_FEELING_GOOD, bionic_data::name, calendar::once_every(), Creature::pain, passive_power_gen(), pkill, pos(), bionic_data::power_over_time, bionic::powered, Creature::remove_effect(), rng(), sounds::sound(), STATIC, and string_id< T >::str().

Referenced by suffer().

◆ process_turn()

void Character::process_turn ( )
overridevirtual

Handles end-of-turn processing.

Reimplemented from Creature.

Reimplemented in npc, and player.

Definition at line 1645 of file character.cpp.

1646{
1647 for( bionic &i : *my_bionics ) {
1648 if( i.incapacitated_time > 0_turns ) {
1649 i.incapacitated_time -= 1_turns;
1650 if( i.incapacitated_time == 0_turns ) {
1651 add_msg_if_player( m_bad, _( "Your %s bionic comes back online." ), i.info().name );
1652 }
1653 }
1654 }
1655
1657}
virtual void process_turn()
Processes effects and bonuses and allocates move points based on speed.
Definition: creature.cpp:156

References _, Creature::add_msg_if_player(), m_bad, my_bionics, and Creature::process_turn().

Referenced by player::process_turn().

◆ query_yn() [1/2]

template<typename ... Args>
bool Character::query_yn ( const char *const  msg,
Args &&...  args 
) const
inline

It is supposed to hide the query_yn to simplify player vs.

npc code.

Definition at line 1437 of file character.h.

1437 {
1438 return query_yn( string_format( msg, std::forward<Args>( args ) ... ) );
1439 }

References query_yn(), and string_format().

Referenced by activate_bionic(), can_install_bionics(), feed_reactor_with(), query_yn(), and will_eat().

◆ query_yn() [2/2]

virtual bool Character::query_yn ( const std::string &  msg) const
pure virtual

Implemented in npc, player, and player.

◆ random_bad_trait()

trait_id Character::random_bad_trait ( )

Returns the id of a random starting trait that costs < 0 points.

Definition at line 2894 of file newcharacter.cpp.

2895{
2896 std::vector<trait_id> vTraitsBad;
2897
2898 for( auto &traits_iter : mutation_branch::get_all() ) {
2899 if( traits_iter.points < 0 && g->scen->traitquery( traits_iter.id ) ) {
2900 vTraitsBad.push_back( traits_iter.id );
2901 }
2902 }
2903
2904 return random_entry( vTraitsBad );
2905}

References g, mutation_branch::get_all(), and random_entry().

Referenced by avatar::randomize().

◆ random_good_trait()

trait_id Character::random_good_trait ( )

Returns the id of a random starting trait that costs >= 0 points.

Definition at line 2881 of file newcharacter.cpp.

2882{
2883 std::vector<trait_id> vTraitsGood;
2884
2885 for( auto &traits_iter : mutation_branch::get_all() ) {
2886 if( traits_iter.points >= 0 && g->scen->traitquery( traits_iter.id ) ) {
2887 vTraitsGood.push_back( traits_iter.id );
2888 }
2889 }
2890
2891 return random_entry( vTraitsGood );
2892}

References g, mutation_branch::get_all(), and random_entry().

Referenced by avatar::randomize().

◆ ranged_dex_mod()

int Character::ranged_dex_mod ( ) const
virtual
Dexterity <20 increases ranged penalty

Definition at line 4145 of file character.cpp.

4146{
4147 ///\EFFECT_DEX <20 increases ranged penalty
4148 return std::max( ( 20.0 - get_dex() ) * 0.5, 0.0 );
4149}

References get_dex().

Referenced by draw_stats_info(), player::get_weapon_dispersion(), and set_stats().

◆ ranged_per_mod()

int Character::ranged_per_mod ( ) const
virtual
Perception <20 increases ranged aiming penalty.

Definition at line 4151 of file character.cpp.

4152{
4153 ///\EFFECT_PER <20 increases ranged aiming penalty.
4154 return std::max( ( 20.0 - get_per() ) * 1.2, 0.0 );
4155}

References get_per().

Referenced by draw_stats_info(), effective_dispersion(), and set_stats().

◆ rate_action_change_side()

hint_rating Character::rate_action_change_side ( const item it) const

Used to determine player feedback on item use for the inventory code.

rates usability lower for non-tools (books, etc.)

Definition at line 3698 of file character.cpp.

3699{
3700 if( !is_worn( it ) ) {
3701 return hint_rating::iffy;
3702 }
3703
3704 if( !it.is_sided() ) {
3705 return hint_rating::cant;
3706 }
3707
3708 return hint_rating::good;
3709}
@ iffy
Item should display as red.
@ cant
Item should display as gray.

References cant, good, iffy, item::is_sided(), and is_worn().

Referenced by game::inventory_item_menu().

◆ rate_action_eat()

hint_rating Character::rate_action_eat ( const item it) const

Definition at line 1256 of file consumption.cpp.

1257{
1258 if( !can_consume( it ) ) {
1259 return hint_rating::cant;
1260 }
1261
1262 const auto rating = will_eat( it );
1263 if( rating.success() ) {
1264 return hint_rating::good;
1265 } else if( rating.value() == edible_rating::inedible ||
1266 rating.value() == edible_rating::inedible_mutation ) {
1267
1268 return hint_rating::cant;
1269 }
1270
1271 return hint_rating::iffy;
1272}
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool can_consume(const item &it) const
Check character's capability of consumption overall.

References can_consume(), cant, good, iffy, inedible, inedible_mutation, and will_eat().

Referenced by game::inventory_item_menu().

◆ react_to_felt_pain()

void Character::react_to_felt_pain ( int  intensity)

Definition at line 853 of file character.cpp.

854{
855 if( intensity <= 0 ) {
856 return;
857 }
858 if( is_player() && intensity >= 2 ) {
859 g->cancel_activity_or_ignore_query( distraction_type::pain, _( "Ouch, something hurts!" ) );
860 }
861 // Only a large pain burst will actually wake people while sleeping.
863 int pain_thresh = rng( 3, 5 );
864
866 pain_thresh += 2;
867 } else if( has_trait( trait_HEAVYSLEEPER2 ) ) {
868 pain_thresh += 5;
869 }
870
871 if( intensity >= pain_thresh ) {
872 wake_up();
873 }
874 }
875}
static const trait_id trait_HEAVYSLEEPER("HEAVYSLEEPER")
static const trait_id trait_HEAVYSLEEPER2("HEAVYSLEEPER2")

References _, effect_narcosis, effect_sleep, g, Creature::has_effect(), has_trait(), Creature::is_player(), pain, rng(), trait_HEAVYSLEEPER, trait_HEAVYSLEEPER2, and wake_up().

Referenced by player::set_pain(), and set_painkiller().

◆ read_speed()

int Character::read_speed ( bool  return_stat_effect = true) const

Returns the player's reading speed.

Intelligence increases reading speed by 3s per level above 8

Definition at line 3425 of file character.cpp.

3426{
3427 // Stat window shows stat effects on based on current stat
3428 const int intel = get_int();
3429 /** @EFFECT_INT increases reading speed by 3s per level above 8*/
3430 int ret = to_moves<int>( 1_minutes ) - to_moves<int>( 3_seconds ) * ( intel - 8 );
3431
3432 if( has_bionic( afs_bio_linguistic_coprocessor ) ) { // Aftershock
3433 ret *= .85;
3434 }
3435
3436 ret *= mutation_value( "reading_speed_multiplier" );
3437
3438 if( ret < to_moves<int>( 1_seconds ) ) {
3439 ret = to_moves<int>( 1_seconds );
3440 }
3441 // return_stat_effect actually matters here
3442 return return_stat_effect ? ret : ret * 100 / to_moves<int>( 1_minutes );
3443}
static const bionic_id afs_bio_linguistic_coprocessor("afs_bio_linguistic_coprocessor")

References afs_bio_linguistic_coprocessor, get_int(), has_bionic(), mutation_value(), and cata::hash64_detail::ret.

Referenced by draw_stats_info(), read_inventory_preset::read_inventory_preset(), set_stats(), npc::time_to_read(), and avatar::time_to_read().

◆ rebuild_mutation_cache()

void Character::rebuild_mutation_cache ( )

Definition at line 8041 of file character.cpp.

8042{
8043 cached_mutations.clear();
8044 for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
8045 cached_mutations.push_back( &mut.first.obj() );
8046 }
8047 for( const trait_id &mut : enchantment_cache->get_mutations() ) {
8048 cached_mutations.push_back( &mut.obj() );
8049 }
8050}

References cached_mutations, enchantment_cache, and my_mutations.

Referenced by set_mutation(), and unset_mutation().

◆ recalc_hp()

void Character::recalc_hp ( )

Recalculates HP after a change to max strength.

Definition at line 1659 of file character.cpp.

1660{
1661 int str_boost_val = 0;
1662 cata::optional<skill_boost> str_boost = skill_boost::get( "str" );
1663 if( str_boost ) {
1664 int skill_total = 0;
1665 for( const std::string &skill_str : str_boost->skills() ) {
1666 skill_total += get_skill_level( skill_id( skill_str ) );
1667 }
1668 str_boost_val = str_boost->calc_bonus( skill_total );
1669 }
1670 // Mutated toughness stacks with starting, by design.
1671 float hp_mod = 1.0f + mutation_value( "hp_modifier" ) + mutation_value( "hp_modifier_secondary" );
1672 float hp_adjustment = mutation_value( "hp_adjustment" ) + ( str_boost_val * 3 );
1673 calc_all_parts_hp( hp_mod, hp_adjustment, str_max );
1674}
void calc_all_parts_hp(float hp_mod=0.0, float hp_adjust=0.0, int str_max=0)
Sets hp for all body parts.
Definition: character.cpp:1676
static cata::optional< skill_boost > get(const std::string &stat_str)
Definition: skill_boost.cpp:20

References calc_all_parts_hp(), skill_boost::get(), get_skill_level(), mutation_value(), skill_id, and str_max.

Referenced by apply_mods(), apply_skill_boost(), avatar::create(), mutation_effect(), mutation_loss_effect(), normalize(), player::normalize(), npc::randomize(), reset_scenario(), set_stats(), and standard_npc::standard_npc().

◆ recalc_sight_limits()

void Character::recalc_sight_limits ( )

Modifies the player's sight values Must be called when any of the following change: This must be called when any of the following change:

  • effects
  • bionics
  • traits
  • underwater
  • clothes

Definition at line 1706 of file character.cpp.

1707{
1708 sight_max = 9999;
1709 vision_mode_cache.reset();
1710
1711 // Set sight_max.
1712 if( is_blind() || ( in_sleep_state() && !has_trait( trait_SEESLEEP ) ) ||
1714 sight_max = 0;
1715 } else if( has_effect( effect_boomered ) && ( !( has_trait( trait_PER_SLIME_OK ) ) ) ) {
1716 sight_max = 1;
1718 } else if( has_effect( effect_in_pit ) || has_effect( effect_no_sight ) ||
1722 sight_max = 1;
1723 } else if( has_active_mutation( trait_SHELL2 ) ) {
1724 // You can kinda see out a bit.
1725 sight_max = 2;
1726 } else if( ( has_trait( trait_MYOPIC ) || has_trait( trait_URSINE_EYE ) ) &&
1728 sight_max = 4;
1729 } else if( has_trait( trait_PER_SLIME ) ) {
1730 sight_max = 6;
1731 } else if( has_effect( effect_darkness ) ) {
1733 sight_max = 10;
1734 }
1735
1736 // Debug-only NV
1739 }
1740
1741 float best_bonus_nv = 0.0f;
1742 for( const mutation_branch *mut : cached_mutations ) {
1743 best_bonus_nv = std::max( best_bonus_nv, mut->night_vision_range );
1744 }
1746 ( is_mounted() && mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) ) {
1747 best_bonus_nv = std::max( best_bonus_nv, 10.0f );
1748 }
1749 if( has_nv() ) {
1751 best_bonus_nv = std::max( best_bonus_nv, 10.0f );
1752 }
1753 if( has_trait( trait_BIRD_EYE ) ) {
1755 }
1756 if( has_trait( trait_URSINE_EYE ) ) {
1758 }
1759
1760 // +1 because of the ugly -1 in _from_per
1763 nv_range += best_bonus_nv;
1765 nv_range++;
1766 }
1767
1768 // Not exactly a sight limit thing, but related enough
1773 mounted_creature->has_flag( MF_MECH_RECON_VISION ) ) ) {
1775 }
1776
1778 has_effect_with_flag( "EFFECT_SUPER_CLAIRVOYANCE" ) ) {
1781 has_effect_with_flag( "EFFECT_CLAIRVOYANCE_PLUS" ) ) {
1783 } else if( has_artifact_with( AEP_CLAIRVOYANCE ) ||
1784 has_effect_with_flag( "EFFECT_CLAIRVOYANCE" ) ) {
1786 }
1787}
static const bionic_id bio_infrared("bio_infrared")
static const std::string flag_FIX_NEARSIGHT("FIX_NEARSIGHT")
static const efftype_id effect_contacts("contacts")
static const trait_id trait_CEPH_EYES("CEPH_EYES")
static const efftype_id effect_boomered("boomered")
static const trait_id trait_INFRARED("INFRARED")
static const trait_id trait_LIZ_IR("LIZ_IR")
static const trait_id trait_URSINE_EYE("URSINE_EYE")
static const trait_id trait_MEMBRANE("MEMBRANE")
static const trait_id trait_MYOPIC("MYOPIC")
static const trait_id trait_BIRD_EYE("BIRD_EYE")
static const efftype_id effect_darkness("darkness")
static const bionic_id bio_membrane("bio_membrane")
static const std::string flag_SWIM_GOGGLES("SWIM_GOGGLES")
static const std::string flag_IR_EFFECT("IR_EFFECT")
static const trait_id trait_DEBUG_NIGHTVISION("DEBUG_NIGHTVISION")
static const trait_id trait_PER_SLIME_OK("PER_SLIME_OK")
static const efftype_id effect_no_sight("no_sight")
@ DARKNESS
Definition: character.h:92
@ URSINE_VISION
Definition: character.h:90
@ IR_VISION
Definition: character.h:93
@ BIRD_EYE
Definition: character.h:89
@ NV_GOGGLES
Definition: character.h:88
@ BOOMERED
Definition: character.h:91
bool is_blind() const
Returns true if the player isn't able to see.
Definition: character.cpp:6357
bool has_nv()
Returns true if the player has some form of night vision.
Definition: character.cpp:3632
int sight_max
Definition: character.h:2111
@ AEP_CLAIRVOYANCE_PLUS
Definition: enums.h:142
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
@ AEP_CLAIRVOYANCE
Definition: enums.h:111
float nv_range_from_per(int per)
Definition: character.cpp:1799
float nv_range_from_eye_encumbrance(int enc)
Definition: character.cpp:1805

References AEP_CLAIRVOYANCE, AEP_CLAIRVOYANCE_PLUS, AEP_SUPER_CLAIRVOYANCE, bio_infrared, bio_membrane, BIRD_EYE, BOOMERED, bp_eyes, cached_mutations, DARKNESS, DEBUG_NIGHTVISION, effect_boomered, effect_contacts, effect_darkness, effect_in_pit, effect_narcosis, effect_no_sight, encumb(), flag_FIX_NEARSIGHT(), flag_IR_EFFECT(), flag_SWIM_GOGGLES(), get_per(), has_active_bionic(), has_active_mutation(), has_artifact_with(), has_bionic(), Creature::has_effect(), Creature::has_effect_with_flag(), has_nv(), has_trait(), in_sleep_state(), IR_VISION, is_blind(), is_mounted(), is_wearing(), itype_rm13_armor_on, MF_MECH_RECON_VISION, mounted_creature, NV_GOGGLES, nv_range, vision::nv_range_from_eye_encumbrance(), vision::nv_range_from_per(), sight_max, trait_BIRD_EYE, trait_CEPH_EYES, trait_DEBUG_NIGHTVISION, trait_INFRARED, trait_LIZ_IR, trait_MEMBRANE, trait_MYOPIC, trait_PER_SLIME, trait_PER_SLIME_OK, trait_SEESLEEP, trait_SHELL2, trait_URSINE_EYE, Creature::underwater, URSINE_VISION, VISION_CLAIRVOYANCE, VISION_CLAIRVOYANCE_PLUS, VISION_CLAIRVOYANCE_SUPER, vision_mode_cache, and worn_with_flag().

Referenced by add_bionic(), deactivate_mutation(), player::environmental_revert_effect(), load(), game::load(), mount_creature(), mutation_spend_resources(), on_item_takeoff(), on_item_wear(), player::player(), remove_bionic(), player::reset_stats(), set_mutation(), player::set_underwater(), player::takeoff(), unset_mutation(), wake_up(), and wear_item().

◆ recalculate_enchantment_cache()

void Character::recalculate_enchantment_cache ( )

Definition at line 8000 of file character.cpp.

8001{
8002 // start by resetting the cache
8004
8005 visit_items( [&]( const item * it ) {
8006 for( const enchantment &ench : it->get_enchantments() ) {
8007 if( ench.is_active( *this, *it ) ) {
8008 enchantment_cache->force_add( ench );
8009 }
8010 }
8011 return VisitResponse::NEXT;
8012 } );
8013
8014 // get from traits/ mutations
8015 for( const std::pair<const trait_id, trait_data> &mut_map : my_mutations ) {
8016 const mutation_branch &mut = mut_map.first.obj();
8017
8018 for( const enchantment_id &ench_id : mut.enchantments ) {
8019 const enchantment &ench = ench_id.obj();
8020 if( ench.is_active( *this, mut.activated && mut_map.second.powered ) ) {
8021 enchantment_cache->force_add( ench );
8022 }
8023 }
8024 }
8025
8026 for( const bionic &bio : *my_bionics ) {
8027 const bionic_id &bid = bio.id;
8028
8029 for( const enchantment_id &ench_id : bid->enchantments ) {
8030 const enchantment &ench = ench_id.obj();
8031 if( ench.is_active( *this, bio.powered &&
8032 bid->has_flag( STATIC( flag_str_id( "BIONIC_TOGGLED" ) ) ) ) ) {
8033 enchantment_cache->force_add( ench );
8034 }
8035 }
8036 }
8037
8039}
void rebuild_mutation_cache()
Definition: character.cpp:8041
bool is_active(const Character &guy, const item &parent) const
std::vector< enchantment > get_enchantments() const
Definition: item.cpp:6817
bool activated
Definition: mutation.h:93

References enchantment_cache, item::get_enchantments(), NEXT, and visitable< Character >::visit_items().

Referenced by activate_bionic(), activate_mutation(), add_bionic(), deactivate_bionic(), deactivate_mutation(), on_mutation_gain(), on_mutation_loss(), remove_bionic(), reset(), update_body(), and player::use().

◆ recalculate_size()

void Character::recalculate_size ( )

Recalculate size class of character.

Definition at line 246 of file mutation.cpp.

247{
249 // Only one size-changing mutation is expected, so it will only use the first one it finds.
250 for( const mutation_branch *mut : cached_mutations ) {
251 if( mut->body_size ) {
252 size_class = *mut->body_size;
253 break;
254 }
255 }
256}

References cached_mutations, MS_MEDIUM, and size_class.

Referenced by load(), mutation_effect(), and mutation_loss_effect().

◆ recoil_mode()

double Character::recoil_mode ( ) const

◆ recoil_total()

double Character::recoil_total ( ) const

Current total maximum recoil penalty from all sources.

Definition at line 2062 of file ranged.cpp.

2063{
2064 return recoil + recoil_vehicle();
2065}
double recoil_vehicle() const
Get maximum recoil penalty due to vehicle motion.
Definition: ranged.cpp:2050

References recoil, and recoil_vehicle().

Referenced by player::fire_gun(), npc::method_of_attack(), npc::move(), target_ui::panel_recoil(), and npc::wont_hit_friend().

◆ recoil_vehicle()

double Character::recoil_vehicle ( ) const

Get maximum recoil penalty due to vehicle motion.

Definition at line 2050 of file ranged.cpp.

2051{
2052 // TODO: vary penalty dependent upon vehicle part on which player is boarded
2053
2054 if( in_vehicle ) {
2055 if( const optional_vpart_position vp = g->m.veh_at( pos() ) ) {
2056 return static_cast<double>( std::abs( vp->vehicle().velocity ) ) * 3 / 100;
2057 }
2058 }
2059 return 0;
2060}

References g, in_vehicle, and pos().

Referenced by player::fire_gun(), print_aim(), and recoil_total().

◆ reduce_healing_effect()

int Character::reduce_healing_effect ( const efftype_id eff_id,
int  remove_med,
const bodypart_id hurt 
)

Reduce healing effect intensity, return initial intensity of the effect.

Definition at line 8629 of file character.cpp.

8631{
8632 const body_part hurt_token = hurt->token;
8633 effect &e = get_effect( eff_id, hurt_token );
8634 int intensity = e.get_intensity();
8635 if( remove_med < intensity ) {
8636 if( eff_id == effect_bandaged ) {
8637 add_msg_if_player( m_bad, _( "Bandages on your %s were damaged!" ), body_part_name( hurt_token ) );
8638 } else if( eff_id == effect_disinfected ) {
8639 add_msg_if_player( m_bad, _( "You got some filth on your disinfected %s!" ),
8640 body_part_name( hurt_token ) );
8641 }
8642 } else {
8643 if( eff_id == effect_bandaged ) {
8644 add_msg_if_player( m_bad, _( "Bandages on your %s were destroyed!" ),
8645 body_part_name( hurt_token ) );
8646 } else if( eff_id == effect_disinfected ) {
8647 add_msg_if_player( m_bad, _( "Your %s is no longer disinfected!" ), body_part_name( hurt_token ) );
8648 }
8649 }
8650 e.mod_duration( -6_hours * remove_med );
8651 return intensity;
8652}

References _, Creature::add_msg_if_player(), body_part_name(), effect_bandaged, effect_disinfected, Creature::get_effect(), effect::get_intensity(), m_bad, and effect::mod_duration().

Referenced by apply_damage().

◆ regen()

void Character::regen ( int  rate_multiplier)

Handles passive regeneration of pain and maybe hp.

Definition at line 4564 of file character.cpp.

4565{
4566 int pain_ticks = rate_multiplier;
4567 while( get_pain() > 0 && pain_ticks-- > 0 ) {
4568 mod_pain( -roll_remainder( 0.2f + get_pain() / 50.0f ) );
4569 }
4570
4571 float rest = rest_quality();
4572 float heal_rate = healing_rate( rest ) * to_turns<int>( 5_minutes );
4573 if( heal_rate > 0.0f ) {
4574 healall( roll_remainder( rate_multiplier * heal_rate ) );
4575 } else if( heal_rate < 0.0f ) {
4576 int rot_rate = roll_remainder( rate_multiplier * -heal_rate );
4577 // Has to be in loop because some effects depend on rounding
4578 while( rot_rate-- > 0 ) {
4579 hurtall( 1, nullptr, false );
4580 }
4581 }
4582
4583 // include healing effects
4584 for( int i = 0; i < num_hp_parts; i++ ) {
4585 const bodypart_id &bp = convert_bp( hp_to_bp( static_cast<hp_part>( i ) ) ).id();
4586 float healing = healing_rate_medicine( rest, bp ) * to_turns<int>( 5_minutes );
4587
4588 int healing_apply = roll_remainder( healing );
4589 healed_bp( i, healing_apply );
4590 heal( bp, healing_apply );
4591 if( damage_bandaged[i] > 0 ) {
4592 damage_bandaged[i] -= healing_apply;
4593 if( damage_bandaged[i] <= 0 ) {
4594 damage_bandaged[i] = 0;
4595 remove_effect( effect_bandaged, bp->token );
4596 add_msg_if_player( _( "Bandaged wounds on your %s healed." ), body_part_name( bp ) );
4597 }
4598 }
4599 if( damage_disinfected[i] > 0 ) {
4600 damage_disinfected[i] -= healing_apply;
4601 if( damage_disinfected[i] <= 0 ) {
4602 damage_disinfected[i] = 0;
4603 remove_effect( effect_disinfected, bp->token );
4604 add_msg_if_player( _( "Disinfected wounds on your %s healed." ), body_part_name( bp ) );
4605 }
4606 }
4607
4608 // remove effects if the limb was healed by other way
4609 if( has_effect( effect_bandaged, bp->token ) && ( get_part( bp )->is_at_max_hp() ) ) {
4610 damage_bandaged[i] = 0;
4611 remove_effect( effect_bandaged, bp->token );
4612 add_msg_if_player( _( "Bandaged wounds on your %s healed." ), body_part_name( bp ) );
4613 }
4614 if( has_effect( effect_disinfected, bp->token ) && ( get_part( bp )->is_at_max_hp() ) ) {
4615 damage_disinfected[i] = 0;
4616 remove_effect( effect_disinfected, bp->token );
4617 add_msg_if_player( _( "Disinfected wounds on your %s healed." ), body_part_name( bp ) );
4618 }
4619 }
4620
4621 if( get_rad() > 0 ) {
4622 mod_rad( -roll_remainder( rate_multiplier / 50.0f ) );
4623 }
4624}
float healing_rate(float at_rest_quality) const
Average hit points healed per turn.
Definition: character.cpp:6778
float healing_rate_medicine(float at_rest_quality, const bodypart_id &bp) const
Average hit points healed per turn from healing effects.
Definition: character.cpp:6820
void healed_bp(int bp, int amount)
Definition: character.cpp:7888
void hurtall(int dam, Creature *source, bool disturb=true)
Hurts all body parts for dam, no armor reduction.
Definition: character.cpp:8671

References _, Creature::add_msg_if_player(), body_part_name(), convert_bp(), damage_bandaged, damage_disinfected, effect_bandaged, effect_disinfected, Creature::get_pain(), Creature::get_part(), get_rad(), Creature::has_effect(), heal(), healall(), healed_bp(), healing_rate(), healing_rate_medicine(), hp_to_bp(), hurtall(), string_id< T >::id(), Creature::mod_pain(), mod_rad(), num_hp_parts, Creature::remove_effect(), rest_quality(), and roll_remainder().

Referenced by update_body().

◆ rem_addiction()

void Character::rem_addiction ( add_type  type)

Removes an addition from the player.

Definition at line 1946 of file suffer.cpp.

1947{
1948 auto iter = std::find_if( addictions.begin(), addictions.end(),
1949 [type]( const addiction & ad ) {
1950 return ad.type == type;
1951 } );
1952
1953 if( iter != addictions.end() ) {
1954 addictions.erase( iter );
1955 g->events().send<event_type::loses_addiction>( getID(), type );
1956 }
1957}

References addictions, g, getID(), loses_addiction, and type.

Referenced by marloss_common(), iuse::mycus(), and suffer_from_addictions().

◆ rem_morale()

void Character::rem_morale ( const morale_type type)

◆ remove_bionic()

void Character::remove_bionic ( const bionic_id b)

Removes a bionic from my_bionics[].

Definition at line 2586 of file bionics.cpp.

2587{
2588 bionic_collection new_my_bionics;
2589 // any spells you should not forget due to still having a bionic installed that has it.
2590 std::set<spell_id> cbm_spells;
2591 for( bionic &i : *my_bionics ) {
2592 if( b == i.id ) {
2593 continue;
2594 }
2595
2596 // Linked bionics: if either is removed, the other is removed as well.
2597 if( b->is_included( i.id ) || i.id->is_included( b ) ) {
2598 continue;
2599 }
2600
2601 for( const std::pair<const spell_id, int> &spell_pair : i.id->learned_spells ) {
2602 cbm_spells.emplace( spell_pair.first );
2603 }
2604
2605 new_my_bionics.push_back( bionic( i.id, i.invlet ) );
2606 }
2607
2608 // any spells you learn from installing a bionic you forget.
2609 for( const std::pair<const spell_id, int> &spell_pair : b->learned_spells ) {
2610 if( cbm_spells.count( spell_pair.first ) == 0 ) {
2611 magic->forget_spell( spell_pair.first );
2612 }
2613 }
2614
2615 *my_bionics = new_my_bionics;
2618 if( !b->enchantments.empty() ) {
2620 }
2621}

References b, magic, my_bionics, recalc_sight_limits(), recalculate_enchantment_cache(), and reset_encumbrance().

Referenced by perform_install(), perform_uninstall(), and uninstall_bionic().

◆ remove_child_flag()

void Character::remove_child_flag ( const trait_id flag)

Removes the mutation's child flag from the player's list.

Definition at line 1496 of file mutation.cpp.

1497{
1498 for( auto &elem : flag->replacements ) {
1499 const trait_id &tmp = elem;
1500 if( has_trait( tmp ) ) {
1501 remove_mutation( tmp );
1502 return;
1503 } else if( has_child_flag( tmp ) ) {
1504 remove_child_flag( tmp );
1505 return;
1506 }
1507 }
1508}

References has_child_flag(), has_trait(), remove_child_flag(), remove_mutation(), and mutation_branch::replacements.

Referenced by mutate_towards(), and remove_child_flag().

◆ remove_mission_items()

void Character::remove_mission_items ( int  mission_id)

Definition at line 2579 of file character.cpp.

2580{
2581 if( mission_id == -1 ) {
2582 return;
2583 }
2584 remove_items_with( has_mission_item_filter { mission_id } );
2585}

References visitable< Character >::remove_items_with().

◆ remove_mutation()

void Character::remove_mutation ( const trait_id mut,
bool  silent = false 
)

Removes a mutation, downgrading to the previous level if possible.

Definition at line 1338 of file mutation.cpp.

1339{
1340 const auto &mdata = mut.obj();
1341 // Check if there's a prerequisite we should shrink back into
1342 trait_id replacing = trait_id::NULL_ID();
1343 std::vector<trait_id> originals = mdata.prereqs;
1344 for( size_t i = 0; !replacing && i < originals.size(); i++ ) {
1345 trait_id pre = originals[i];
1346 const auto &p = pre.obj();
1347 for( size_t j = 0; !replacing && j < p.replacements.size(); j++ ) {
1348 if( p.replacements[j] == mut ) {
1349 replacing = pre;
1350 }
1351 }
1352 }
1353
1354 trait_id replacing2 = trait_id::NULL_ID();
1355 std::vector<trait_id> originals2 = mdata.prereqs2;
1356 for( size_t i = 0; !replacing2 && i < originals2.size(); i++ ) {
1357 trait_id pre2 = originals2[i];
1358 const auto &p = pre2.obj();
1359 for( size_t j = 0; !replacing2 && j < p.replacements.size(); j++ ) {
1360 if( p.replacements[j] == mut ) {
1361 replacing2 = pre2;
1362 }
1363 }
1364 }
1365
1366 // See if this mutation is canceled by a base trait
1367 //Only if there's no prerequisite to shrink to, thus we're at the bottom of the trait line
1368 if( !replacing ) {
1369 //Check each mutation until we reach the end or find a trait to revert to
1370 for( auto &iter : mutation_branch::get_all() ) {
1371 //See if it's in our list of base traits but not active
1372 if( has_base_trait( iter.id ) && !has_trait( iter.id ) ) {
1373 //See if that base trait cancels the mutation we are using
1374 std::vector<trait_id> traitcheck = iter.cancels;
1375 if( !traitcheck.empty() ) {
1376 for( size_t j = 0; !replacing && j < traitcheck.size(); j++ ) {
1377 if( traitcheck[j] == mut ) {
1378 replacing = ( iter.id );
1379 }
1380 }
1381 }
1382 }
1383 if( replacing ) {
1384 break;
1385 }
1386 }
1387 }
1388
1389 // Duplicated for prereq2
1390 if( !replacing2 ) {
1391 //Check each mutation until we reach the end or find a trait to revert to
1392 for( auto &iter : mutation_branch::get_all() ) {
1393 //See if it's in our list of base traits but not active
1394 if( has_base_trait( iter.id ) && !has_trait( iter.id ) ) {
1395 //See if that base trait cancels the mutation we are using
1396 std::vector<trait_id> traitcheck = iter.cancels;
1397 if( !traitcheck.empty() ) {
1398 for( size_t j = 0; !replacing2 && j < traitcheck.size(); j++ ) {
1399 if( traitcheck[j] == mut && ( iter.id ) != replacing ) {
1400 replacing2 = ( iter.id );
1401 }
1402 }
1403 }
1404 }
1405 if( replacing2 ) {
1406 break;
1407 }
1408 }
1409 }
1410
1411 // make sure we don't toggle a mutation or trait twice, or it will cancel itself out.
1412 if( replacing == replacing2 ) {
1413 replacing2 = trait_id::NULL_ID();
1414 }
1415
1416 // This should revert back to a removed base trait rather than simply removing the mutation
1417 unset_mutation( mut );
1418
1419 bool mutation_replaced = false;
1420
1421 game_message_type rating;
1422
1423 if( replacing ) {
1424 const auto &replace_mdata = replacing.obj();
1425 if( mdata.mixed_effect || replace_mdata.mixed_effect ) {
1426 rating = m_mixed;
1427 } else if( replace_mdata.points - mdata.points > 0 ) {
1428 rating = m_good;
1429 } else if( mdata.points - replace_mdata.points > 0 ) {
1430 rating = m_bad;
1431 } else {
1432 rating = m_neutral;
1433 }
1434 if( !silent ) {
1435 add_msg_player_or_npc( rating,
1436 _( "Your %1$s mutation turns into %2$s." ),
1437 _( "<npcname>'s %1$s mutation turns into %2$s." ),
1438 mdata.name(), replace_mdata.name() );
1439 }
1440 set_mutation( replacing );
1441 mutation_replaced = true;
1442 }
1443 if( replacing2 ) {
1444 const auto &replace_mdata = replacing2.obj();
1445 if( mdata.mixed_effect || replace_mdata.mixed_effect ) {
1446 rating = m_mixed;
1447 } else if( replace_mdata.points - mdata.points > 0 ) {
1448 rating = m_good;
1449 } else if( mdata.points - replace_mdata.points > 0 ) {
1450 rating = m_bad;
1451 } else {
1452 rating = m_neutral;
1453 }
1454 if( !silent ) {
1455 add_msg_player_or_npc( rating,
1456 _( "Your %1$s mutation turns into %2$s." ),
1457 _( "<npcname>'s %1$s mutation turns into %2$s." ),
1458 mdata.name(), replace_mdata.name() );
1459 }
1460 set_mutation( replacing2 );
1461 mutation_replaced = true;
1462 }
1463 if( !mutation_replaced ) {
1464 if( mdata.mixed_effect ) {
1465 rating = m_mixed;
1466 } else if( mdata.points > 0 ) {
1467 rating = m_bad;
1468 } else if( mdata.points < 0 ) {
1469 rating = m_good;
1470 } else {
1471 rating = m_neutral;
1472 }
1473 if( !silent ) {
1474 add_msg_player_or_npc( rating,
1475 _( "You lose your %s mutation." ),
1476 _( "<npcname> loses their %s mutation." ),
1477 mdata.name() );
1478 }
1479 }
1480
1483}
@ silent
Definition: weather_type.h:56

References _, Creature::add_msg_player_or_npc(), drench_mut_calc(), mutation_branch::get_all(), has_base_trait(), has_trait(), m_bad, m_good, m_mixed, m_neutral, string_id< mutation_branch >::NULL_ID(), string_id< T >::obj(), set_highest_cat_level(), set_mutation(), silent, and unset_mutation().

Referenced by do_purify(), player::load(), mutate(), mutate_towards(), old_mutate(), perform_install(), iuse::purify_iv(), iuse::purify_smart(), remove_child_flag(), and debug_menu::wishmutate().

◆ remove_weapon()

item Character::remove_weapon ( )

Definition at line 2571 of file character.cpp.

2572{
2573 item tmp = weapon;
2574 weapon = item();
2575 cached_info.erase( "weapon_value" );
2576 return tmp;
2577}

References cached_info, and weapon.

Referenced by talk_function::drop_weapon(), melee_special_effects(), perform_technique(), mattack::pull_metal_weapon(), smash(), npc::stow_item(), and use_amount().

◆ remove_worn_items_with()

std::list< item > Character::remove_worn_items_with ( std::function< bool(item &)>  filter)

Similar to remove_items_with, but considers only worn items and not their content (item::contents is not checked).

If the filter function returns true, the item is removed.

Definition at line 2350 of file character.cpp.

2351{
2352 std::list<item> result;
2353 for( auto iter = worn.begin(); iter != worn.end(); ) {
2354 if( filter( *iter ) ) {
2355 iter->on_takeoff( *this );
2356 result.splice( result.begin(), worn, iter++ );
2357 } else {
2358 ++iter;
2359 }
2360 }
2361 return result;
2362}

References worn.

Referenced by mutation_effect(), and player::process_items().

◆ reset()

void Character::reset ( )
overridevirtual

Handles stat and bonus reset.

Reimplemented from Creature.

Definition at line 3625 of file character.cpp.

3626{
3628 // TODO: Move reset_stats here, remove it from Creature
3630}
virtual void reset()
Handles stat and bonus reset.
Definition: creature.cpp:125

References recalculate_enchantment_cache(), and Creature::reset().

Referenced by activate_bionic(), deactivate_bionic(), game::load(), and set_stats().

◆ reset_bonuses()

void Character::reset_bonuses ( )
overridevirtual

Resets the value of all bonus fields to 0.

Reimplemented from Creature.

Definition at line 4541 of file character.cpp.

4542{
4543 // Reset all bonuses to 0 and multipliers to 1.0
4544 str_bonus = 0;
4545 dex_bonus = 0;
4546 per_bonus = 0;
4547 int_bonus = 0;
4548
4550}
virtual void reset_bonuses()
Resets the value of all bonus fields to 0.
Definition: creature.cpp:139

References dex_bonus, int_bonus, per_bonus, Creature::reset_bonuses(), and str_bonus.

◆ reset_chargen_attributes()

void Character::reset_chargen_attributes ( )

Definition at line 6894 of file character.cpp.

6895{
6896 init_age = 25;
6897 init_height = 175;
6898}

References init_age, and init_height.

◆ reset_encumbrance()

◆ reset_remote_fuel()

void Character::reset_remote_fuel ( )

Definition at line 1447 of file bionics.cpp.

1448{
1449 if( get_bionic_fueled_with( item( fuel_type_sun_light ) ).empty() ) {
1450 remove_value( "sunlight" );
1451 }
1452 remove_value( "rem_battery" );
1453}

References fuel_type_sun_light, get_bionic_fueled_with(), and Creature::remove_value().

Referenced by iuse::cable_attach(), and deactivate_bionic().

◆ reset_stats()

void Character::reset_stats ( )
overridevirtual

Resets stats, and applies effects in an idempotent manner.

Implements Creature.

Reimplemented in player.

Definition at line 3580 of file character.cpp.

3581{
3582 // Bionic buffs
3584 mod_str_bonus( 20 );
3585 }
3586
3591
3592 // Trait / mutation buffs
3593 mod_str_bonus( std::floor( mutation_value( "str_modifier" ) ) );
3594 mod_dodge_bonus( std::floor( mutation_value( "dodge_modifier" ) ) );
3595
3597
3598 nv_cached = false;
3599
3600 // Reset our stats to normal levels
3601 // Any persistent buffs/debuffs will take place in effects,
3602 // player::suffer(), etc.
3603
3604 // repopulate the stat fields
3609
3610 // Floor for our stats. No stat changes should occur after this!
3611 if( dex_cur < 0 ) {
3612 dex_cur = 0;
3613 }
3614 if( str_cur < 0 ) {
3615 str_cur = 0;
3616 }
3617 if( per_cur < 0 ) {
3618 per_cur = 0;
3619 }
3620 if( int_cur < 0 ) {
3621 int_cur = 0;
3622 }
3623}
static const bionic_id bio_hydraulics("bio_hydraulics")
virtual int get_str_bonus() const
Definition: character.cpp:4114
virtual int get_int_bonus() const
Definition: character.cpp:4126
int get_mod_stat_from_bionic(const character_stat &Stat) const
Get stat bonus from bionic.
Definition: character.cpp:2172
virtual int get_per_bonus() const
Definition: character.cpp:4122
void apply_skill_boost()
Applies skill-based boosts to stats.
Definition: character.cpp:3504
virtual int get_dex_bonus() const
Definition: character.cpp:4118
virtual void mod_dodge_bonus(float ndodge)
Definition: creature.cpp:1761

References apply_skill_boost(), bio_hydraulics, dex_cur, dex_max, DEXTERITY, get_dex_bonus(), get_int_bonus(), get_mod_stat_from_bionic(), get_per_bonus(), get_str_bonus(), has_active_bionic(), int_cur, int_max, INTELLIGENCE, mod_dex_bonus(), Creature::mod_dodge_bonus(), mod_int_bonus(), mod_per_bonus(), mod_str_bonus(), mutation_value(), nv_cached, per_cur, per_max, PERCEPTION, str_cur, str_max, and STRENGTH.

Referenced by player::reset_stats().

◆ rest_quality()

float Character::rest_quality ( ) const

Returns >0 if character is sitting/lying and relatively inactive.

1 represents sleep on comfortable bed, so anything above that should be rare.

Definition at line 6571 of file character.cpp.

6572{
6573 // Just a placeholder for now.
6574 // TODO: Waiting/reading/being unconscious on bed/sofa/grass
6575 return has_effect( effect_sleep ) ? 1.0f : 0.0f;
6576}

References effect_sleep, and Creature::has_effect().

Referenced by mend(), and regen().

◆ restore_scent()

void Character::restore_scent ( )

restore scent after masked_scent effect run out or is removed by water

Definition at line 8778 of file character.cpp.

8779{
8780 const std::string prev_scent = get_value( "prev_scent" );
8781 if( !prev_scent.empty() ) {
8783 set_type_of_scent( scenttype_id( prev_scent ) );
8784 remove_value( "prev_scent" );
8785 remove_value( "waterproof_scent" );
8786 add_msg_if_player( m_info, _( "You smell like yourself again." ) );
8787 }
8788}
static const efftype_id effect_masked_scent("masked_scent")
void set_type_of_scent(const scenttype_id &id)
Definition: character.cpp:8768
string_id< scent_type > scenttype_id
Definition: type_id.h:35

References _, Creature::add_msg_if_player(), effect_masked_scent, Creature::get_value(), m_info, Creature::remove_effect(), Creature::remove_value(), and set_type_of_scent().

Referenced by drench(), and player::process_turn().

◆ resume_backlog_activity()

void Character::resume_backlog_activity ( )

Definition at line 9278 of file character.cpp.

9279{
9280 if( !backlog.empty() && backlog.front().auto_resume ) {
9281 activity = backlog.front();
9282 backlog.pop_front();
9283 }
9284}

References activity, and backlog.

Referenced by game::cancel_activity_query(), and player_activity::do_turn().

◆ roll_all_damage()

void Character::roll_all_damage ( bool  crit,
damage_instance di,
bool  average,
const item weap 
) const

Adds all 3 types of physical damage to instance.

Definition at line 351 of file melee.cpp.

353{
354 roll_bash_damage( crit, di, average, weap );
355 roll_cut_damage( crit, di, average, weap );
356 roll_stab_damage( crit, di, average, weap );
357}
void roll_stab_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds player's total stab damage to the damage instance.
Definition: melee.cpp:1047
void roll_bash_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds player's total bash damage to the damage instance.
Definition: melee.cpp:869
void roll_cut_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds player's total cut damage to the damage instance.
Definition: melee.cpp:973

References roll_bash_damage(), roll_cut_damage(), and roll_stab_damage().

Referenced by item::effective_dps(), and melee_attack().

◆ roll_bash_damage()

void Character::roll_bash_damage ( bool  crit,
damage_instance di,
bool  average,
const item weap 
) const

Adds player's total bash damage to the damage instance.

Strength increases bashing damage Strength increases bashing damage Unarmed caps bash damage with unarmed weapons Bashing caps bash damage with bashing weapons Strength boosts low cap on bashing damage

Definition at line 869 of file melee.cpp.

871{
872 float bash_dam = 0.0f;
873
874 const bool unarmed = weap.is_unarmed_weapon();
875 int skill = get_skill_level( unarmed ? skill_unarmed : skill_bashing );
876 if( has_active_bionic( bio_cqb ) ) {
877 skill = BIO_CQB_LEVEL;
878 }
879
880 const int stat = get_str();
881 /** @EFFECT_STR increases bashing damage */
882 float stat_bonus = bonus_damage( !average );
883 stat_bonus += mabuff_damage_bonus( DT_BASH );
884
885 // Drunken Master damage bonuses
887 // Remember, a single drink gives 600 levels of "drunk"
888 int mindrunk = 0;
889 int maxdrunk = 0;
890 const time_duration drunk_dur = get_effect_dur( effect_drunk );
891 if( unarmed ) {
892 mindrunk = drunk_dur / 1_hours;
893 maxdrunk = drunk_dur / 25_minutes;
894 } else {
895 mindrunk = drunk_dur / 90_minutes;
896 maxdrunk = drunk_dur / 40_minutes;
897 }
898
899 bash_dam += average ? ( mindrunk + maxdrunk ) * 0.5f : rng( mindrunk, maxdrunk );
900 }
901
902 if( unarmed ) {
903 const bool left_empty = !natural_attack_restricted_on( bodypart_id( "hand_l" ) );
904 const bool right_empty = !natural_attack_restricted_on( bodypart_id( "hand_r" ) ) &&
905 weap.is_null();
906 if( left_empty || right_empty ) {
907 float per_hand = 0.0f;
908 for( const trait_id &mut : get_mutations() ) {
909 if( mut->flags.count( "NEED_ACTIVE_TO_MELEE" ) > 0 && !has_active_mutation( mut ) ) {
910 continue;
911 }
912 float unarmed_bonus = 0.0f;
913 const int bash_bonus = mut->bash_dmg_bonus;
914 if( mut->flags.count( "UNARMED_BONUS" ) > 0 && bash_bonus > 0 ) {
915 unarmed_bonus += std::min( get_skill_level( skill_unarmed ) / 2, 4 );
916 }
917 per_hand += bash_bonus + unarmed_bonus;
918 const std::pair<int, int> rand_bash = mut->rand_bash_bonus;
919 per_hand += average ? ( rand_bash.first + rand_bash.second ) / 2.0f : rng( rand_bash.first,
920 rand_bash.second );
921 }
922 bash_dam += per_hand; // First hand
923 if( left_empty && right_empty ) {
924 // Second hand
925 bash_dam += per_hand;
926 }
927 }
928
929 }
930
931 /** @EFFECT_STR increases bashing damage */
932 float weap_dam = weap.damage_melee( DT_BASH ) + stat_bonus;
933 /** @EFFECT_UNARMED caps bash damage with unarmed weapons */
934
935 /** @EFFECT_BASHING caps bash damage with bashing weapons */
936 float bash_cap = 2 * stat + 2 * skill;
937 float bash_mul = 1.0f;
938
939 // 80%, 88%, 96%, 104%, 112%, 116%, 120%, 124%, 128%, 132%
940 if( skill < 5 ) {
941 bash_mul = 0.8 + 0.08 * skill;
942 } else {
943 bash_mul = 0.96 + 0.04 * skill;
944 }
945
946 if( bash_cap < weap_dam && !weap.is_null() ) {
947 // If damage goes over cap due to low stats/skills,
948 // scale the post-armor damage down halfway between damage and cap
949 bash_mul *= ( 1.0f + ( bash_cap / weap_dam ) ) / 2.0f;
950 }
951
952 /** @EFFECT_STR boosts low cap on bashing damage */
953 const float low_cap = std::min( 1.0f, stat / 20.0f );
954 const float bash_min = low_cap * weap_dam;
955 weap_dam = average ? ( bash_min + weap_dam ) * 0.5f : rng_float( bash_min, weap_dam );
956
957 bash_dam += weap_dam;
958 bash_mul *= mabuff_damage_mult( DT_BASH );
959
960 float armor_mult = 1.0f;
961 int arpen = mabuff_arpen_bonus( DT_BASH );
962
963 // Finally, extra critical effects
964 if( crit ) {
965 bash_mul *= 1.5f;
966 // 50% armor penetration
967 armor_mult = 0.5f;
968 }
969
970 di.add_damage( DT_BASH, bash_dam, arpen, armor_mult, bash_mul );
971}
int mabuff_arpen_bonus(damage_type type) const
Returns the arpen bonus from martial arts buffs.
float bonus_damage(bool random) const
Returns the bonus bashing damage the player deals based on their stats.
Definition: melee.cpp:859
bool natural_attack_restricted_on(const bodypart_id &bp) const
Returns true if the character is wearing something on the entered body_part, ignoring items with the ...
Definition: character.cpp:1859
int mabuff_damage_bonus(damage_type type) const
Returns the flat damage bonus to given type from martial arts buffs, applied after the multiplier.
float mabuff_damage_mult(damage_type type) const
Returns the damage multiplier to given type from martial arts buffs.
static const efftype_id effect_drunk("drunk")
static const trait_id trait_DRUNKEN("DRUNKEN")
static const skill_id skill_bashing("bashing")

References damage_instance::add_damage(), bio_cqb, BIO_CQB_LEVEL, bonus_damage(), item::damage_melee(), DT_BASH, effect_drunk, Creature::get_effect_dur(), get_mutations(), get_skill_level(), get_str(), has_active_bionic(), has_active_mutation(), Creature::has_effect(), has_trait(), item::is_null(), item::is_unarmed_weapon(), mabuff_arpen_bonus(), mabuff_damage_bonus(), mabuff_damage_mult(), natural_attack_restricted_on(), rng(), rng_float(), skill_bashing, skill_unarmed, and trait_DRUNKEN.

Referenced by roll_all_damage().

◆ roll_cut_damage()

void Character::roll_cut_damage ( bool  crit,
damage_instance di,
bool  average,
const item weap 
) const

Adds player's total cut damage to the damage instance.

Cutting increases cutting damage multiplier

Definition at line 973 of file melee.cpp.

975{
976 float cut_dam = mabuff_damage_bonus( DT_CUT ) + weap.damage_melee( DT_CUT );
977 float cut_mul = 1.0f;
978
979 int cutting_skill = get_skill_level( skill_cutting );
980
981 if( has_active_bionic( bio_cqb ) ) {
982 cutting_skill = BIO_CQB_LEVEL;
983 }
984
985 if( weap.is_unarmed_weapon() ) {
986 // TODO: 1-handed weapons that aren't unarmed attacks
987 const bool left_empty = !natural_attack_restricted_on( bodypart_id( "hand_l" ) );
988 const bool right_empty = !natural_attack_restricted_on( bodypart_id( "hand_r" ) ) &&
989 weap.is_null();
990 if( left_empty || right_empty ) {
991 float per_hand = 0.0f;
992 if( has_bionic( bionic_id( "bio_razors" ) ) ) {
993 per_hand += 2;
994 }
995
996 for( const trait_id &mut : get_mutations() ) {
997 if( mut->flags.count( "NEED_ACTIVE_TO_MELEE" ) > 0 && !has_active_mutation( mut ) ) {
998 continue;
999 }
1000 float unarmed_bonus = 0.0f;
1001 const int cut_bonus = mut->cut_dmg_bonus;
1002 if( mut->flags.count( "UNARMED_BONUS" ) > 0 && cut_bonus > 0 ) {
1003 unarmed_bonus += std::min( get_skill_level( skill_unarmed ) / 2, 4 );
1004 }
1005 per_hand += cut_bonus + unarmed_bonus;
1006 const std::pair<int, int> rand_cut = mut->rand_cut_bonus;
1007 per_hand += average ? ( rand_cut.first + rand_cut.second ) / 2.0f : rng( rand_cut.first,
1008 rand_cut.second );
1009 }
1010 // TODO: add acidproof check back to slime hands (probably move it elsewhere)
1011
1012 cut_dam += per_hand; // First hand
1013 if( left_empty && right_empty ) {
1014 // Second hand
1015 cut_dam += per_hand;
1016 }
1017 }
1018 }
1019
1020 if( cut_dam <= 0.0f ) {
1021 return; // No negative damage!
1022 }
1023
1024 int arpen = 0;
1025 float armor_mult = 1.0f;
1026
1027 // 80%, 88%, 96%, 104%, 112%, 116%, 120%, 124%, 128%, 132%
1028 /** @EFFECT_CUTTING increases cutting damage multiplier */
1029 if( cutting_skill < 5 ) {
1030 cut_mul *= 0.8 + 0.08 * cutting_skill;
1031 } else {
1032 cut_mul *= 0.96 + 0.04 * cutting_skill;
1033 }
1034
1035 arpen += mabuff_arpen_bonus( DT_CUT );
1036
1037 cut_mul *= mabuff_damage_mult( DT_CUT );
1038 if( crit ) {
1039 cut_mul *= 1.25f;
1040 arpen += 5;
1041 armor_mult = 0.75f; //25% armor penetration
1042 }
1043
1044 di.add_damage( DT_CUT, cut_dam, arpen, armor_mult, cut_mul );
1045}
static const skill_id skill_cutting("cutting")

References damage_instance::add_damage(), bio_cqb, BIO_CQB_LEVEL, bionic_id, item::damage_melee(), DT_CUT, get_mutations(), get_skill_level(), has_active_bionic(), has_active_mutation(), has_bionic(), item::is_null(), item::is_unarmed_weapon(), mabuff_arpen_bonus(), mabuff_damage_bonus(), mabuff_damage_mult(), natural_attack_restricted_on(), rng(), skill_cutting, and skill_unarmed.

Referenced by roll_all_damage().

◆ roll_stab_damage()

void Character::roll_stab_damage ( bool  crit,
damage_instance di,
bool  average,
const item weap 
) const

Adds player's total stab damage to the damage instance.

Stabbing increases stabbing damage multiplier

Definition at line 1047 of file melee.cpp.

1049{
1050 float stab_dam = mabuff_damage_bonus( DT_STAB ) + weap.damage_melee( DT_STAB );
1051
1052 int unarmed_skill = get_skill_level( skill_unarmed );
1053 int stabbing_skill = get_skill_level( skill_stabbing );
1054
1055 if( has_active_bionic( bio_cqb ) ) {
1056 stabbing_skill = BIO_CQB_LEVEL;
1057 }
1058
1059 if( weap.is_unarmed_weapon() ) {
1060 const bool left_empty = !natural_attack_restricted_on( bodypart_id( "hand_l" ) );
1061 const bool right_empty = !natural_attack_restricted_on( bodypart_id( "hand_r" ) ) &&
1062 weap.is_null();
1063 if( left_empty || right_empty ) {
1064 float per_hand = 0.0f;
1065
1066 for( const trait_id &mut : get_mutations() ) {
1067 int stab_bonus = mut->pierce_dmg_bonus;
1068 int unarmed_bonus = 0;
1069 if( mut->flags.count( "UNARMED_BONUS" ) > 0 && stab_bonus > 0 ) {
1070 unarmed_bonus = std::min( unarmed_skill / 2, 4 );
1071 }
1072
1073 per_hand += stab_bonus + unarmed_bonus;
1074 }
1075
1076 if( has_bionic( bionic_id( "bio_razors" ) ) ) {
1077 per_hand += 2;
1078 }
1079
1080 stab_dam += per_hand; // First hand
1081 if( left_empty && right_empty ) {
1082 // Second hand
1083 stab_dam += per_hand;
1084 }
1085 }
1086 }
1087
1088 if( stab_dam <= 0 ) {
1089 return; // No negative stabbing!
1090 }
1091
1092 float stab_mul = 1.0f;
1093 // 66%, 76%, 86%, 96%, 106%, 116%, 122%, 128%, 134%, 140%
1094 /** @EFFECT_STABBING increases stabbing damage multiplier */
1095 if( stabbing_skill <= 5 ) {
1096 stab_mul = 0.66 + 0.1 * stabbing_skill;
1097 } else {
1098 stab_mul = 0.86 + 0.06 * stabbing_skill;
1099 }
1100 int arpen = mabuff_arpen_bonus( DT_STAB );
1101 stab_mul *= mabuff_damage_mult( DT_STAB );
1102 float armor_mult = 1.0f;
1103
1104 if( crit ) {
1105 // Critical damage bonus for stabbing scales with skill
1106 stab_mul *= 1.0 + ( stabbing_skill / 10.0 );
1107 // Stab criticals have extra %arpen
1108 armor_mult = 0.66f;
1109 }
1110
1111 di.add_damage( DT_STAB, stab_dam, arpen, armor_mult, stab_mul );
1112}
static const skill_id skill_stabbing("stabbing")

References damage_instance::add_damage(), bio_cqb, BIO_CQB_LEVEL, bionic_id, item::damage_melee(), DT_STAB, get_mutations(), get_skill_level(), has_active_bionic(), has_bionic(), item::is_null(), item::is_unarmed_weapon(), mabuff_arpen_bonus(), mabuff_damage_bonus(), mabuff_damage_mult(), natural_attack_restricted_on(), skill_stabbing, and skill_unarmed.

Referenced by roll_all_damage().

◆ rooted()

void Character::rooted ( )

Definition at line 8856 of file character.cpp.

8858{
8859 double shoe_factor = footwear_factor();
8860 if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
8861 get_map().has_flag( flag_PLOWABLE, pos() ) && shoe_factor != 1.0 ) {
8862 if( one_in( 96 ) ) {
8863 vitamin_mod( vitamin_id( "iron" ), 1, true );
8864 vitamin_mod( vitamin_id( "calcium" ), 1, true );
8865 }
8866 if( get_thirst() <= thirst_levels::turgid && x_in_y( 75, 425 ) ) {
8867 mod_thirst( -1 );
8868 }
8869 mod_healthy_mod( 5, 50 );
8870 }
8871}
static const std::string flag_PLOWABLE("PLOWABLE")
int vitamin_mod(const vitamin_id &vit, int qty, bool capped=true)
Add or subtract vitamins from character storage pools.
string_id< vitamin > vitamin_id
Definition: type_id.h:180

References flag_PLOWABLE(), footwear_factor(), get_map(), get_thirst(), Creature::has_flag(), has_trait(), mod_healthy_mod(), mod_thirst(), one_in(), pos(), trait_ROOTS2, trait_ROOTS3, turgid, vitamin_mod(), and x_in_y().

Referenced by player_activity::do_turn().

◆ rooted_message()

void Character::rooted_message ( ) const

Handles rooting effects.

Definition at line 8846 of file character.cpp.

8847{
8848 bool wearing_shoes = is_wearing_shoes( side::LEFT ) || is_wearing_shoes( side::RIGHT );
8849 if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) &&
8851 !wearing_shoes ) {
8852 add_msg( m_info, _( "You sink your roots into the soil." ) );
8853 }
8854}

References _, add_msg(), flag_PLOWABLE(), get_map(), Creature::has_flag(), has_trait(), is_wearing_shoes(), LEFT, m_info, pos(), RIGHT, trait_ROOTS2, and trait_ROOTS3.

Referenced by player_activity::start_or_resume().

◆ run_cost()

int Character::run_cost ( int  base_cost,
bool  diag = false 
) const

Returns the player's modified base movement cost.

Definition at line 10029 of file character.cpp.

10030{
10031 float movecost = static_cast<float>( base_cost );
10032 if( diag ) {
10033 movecost *= 0.7071f; // because everything here assumes 100 is base
10034 }
10035 const bool flatground = movecost < 105;
10036 map &here = get_map();
10037 // The "FLAT" tag includes soft surfaces, so not a good fit.
10038 const bool on_road = flatground && here.has_flag( "ROAD", pos() );
10039 const bool on_fungus = here.has_flag_ter_or_furn( "FUNGUS", pos() );
10040
10041 if( !is_mounted() ) {
10042 if( movecost > 100 ) {
10043 movecost *= mutation_value( "movecost_obstacle_modifier" );
10044 if( movecost < 100 ) {
10045 movecost = 100;
10046 }
10047 }
10048 if( has_trait( trait_M_IMMUNE ) && on_fungus ) {
10049 if( movecost > 75 ) {
10050 // Mycal characters are faster on their home territory, even through things like shrubs
10051 movecost = 75;
10052 }
10053 }
10054
10055 // Linearly increase move cost relative to individual leg hp.
10056 movecost += 50 * ( 1 - static_cast<float>( get_part_hp_cur( bodypart_id( "leg_l" ) ) ) /
10057 static_cast<float>( get_part_hp_max( bodypart_id( "leg_l" ) ) ) );
10058 movecost += 50 * ( 1 - static_cast<float>( get_part_hp_cur( bodypart_id( "leg_r" ) ) ) /
10059 static_cast<float>( get_part_hp_max( bodypart_id( "leg_r" ) ) ) );
10060 movecost *= mutation_value( "movecost_modifier" );
10061 if( flatground ) {
10062 movecost *= mutation_value( "movecost_flatground_modifier" );
10063 }
10065 movecost *= .9f;
10066 }
10068 if( move_mode == CMM_RUN ) {
10069 movecost *= 0.85f;
10070 } else {
10071 movecost *= 0.95f;
10072 }
10073 } else if( has_bionic( bio_jointservo ) ) {
10074 movecost *= 1.1f;
10075 }
10076
10077 if( worn_with_flag( "SLOWS_MOVEMENT" ) ) {
10078 movecost *= 1.1f;
10079 }
10080 if( worn_with_flag( "FIN" ) ) {
10081 movecost *= 1.5f;
10082 }
10083 if( worn_with_flag( "ROLLER_INLINE" ) ) {
10084 if( on_road ) {
10085 movecost *= 0.5f;
10086 } else {
10087 movecost *= 1.5f;
10088 }
10089 }
10090 // Quad skates might be more stable than inlines,
10091 // but that also translates into a slower speed when on good surfaces.
10092 if( worn_with_flag( "ROLLER_QUAD" ) ) {
10093 if( on_road ) {
10094 movecost *= 0.7f;
10095 } else {
10096 movecost *= 1.3f;
10097 }
10098 }
10099 // Skates with only one wheel (roller shoes) are fairly less stable
10100 // and fairly slower as well
10101 if( worn_with_flag( "ROLLER_ONE" ) ) {
10102 if( on_road ) {
10103 movecost *= 0.85f;
10104 } else {
10105 movecost *= 1.1f;
10106 }
10107 }
10108
10109 movecost +=
10110 ( ( encumb( bp_foot_l ) + encumb( bp_foot_r ) ) * 2.5 +
10111 ( encumb( bp_leg_l ) + encumb( bp_leg_r ) ) * 1.5 ) / 10;
10112
10113 // ROOTS3 does slow you down as your roots are probing around for nutrients,
10114 // whether you want them to or not. ROOTS1 is just too squiggly without shoes
10115 // to give you some stability. Plants are a bit of a slow-mover. Deal.
10116 if( has_trait( trait_ROOTS3 ) && here.has_flag( "DIGGABLE", pos() ) ) {
10117 movecost += 10 * footwear_factor();
10118 }
10119
10121 movecost /= stamina_move_cost_modifier();
10122
10123 if( movecost < 20.0 ) {
10124 movecost = 20.0;
10125 }
10126 }
10127
10128 if( diag ) {
10129 movecost *= M_SQRT2;
10130 }
10131
10132 return static_cast<int>( movecost );
10133}
static const trait_id trait_M_IMMUNE("M_IMMUNE")
static const trait_id trait_PADDED_FEET("PADDED_FEET")
static const bionic_id bio_jointservo("bio_jointservo")
#define M_SQRT2
Definition: math_defines.h:29

References bio_jointservo, bonus_from_enchantments(), bp_foot_l, bp_foot_r, bp_leg_l, bp_leg_r, CMM_RUN, encumb(), footwear_factor(), get_map(), Creature::get_part_hp_cur(), Creature::get_part_hp_max(), has_active_bionic(), has_bionic(), map::has_flag(), map::has_flag_ter_or_furn(), has_trait(), is_mounted(), M_SQRT2, enchant_vals::MOVE_COST, move_mode, mutation_value(), pos(), stamina_move_cost_modifier(), trait_M_IMMUNE, trait_PADDED_FEET, trait_ROOTS3, and worn_with_flag().

Referenced by draw_speed_tab(), npc::move_to(), speed_description(), speed_rating(), npc::speed_rating(), and game::walk_move().

◆ rust_rate()

int Character::rust_rate ( ) const

Returns the player's skill rust rate.

Intelligence reduces skill rust by 10% per level above 8

Definition at line 3403 of file character.cpp.

3404{
3405 const std::string &rate_option = get_option<std::string>( "SKILL_RUST" );
3406 if( rate_option == "off" ) {
3407 return 0;
3408 }
3409
3410 // Stat window shows stat effects on based on current stat
3411 int intel = get_int();
3412 /** @EFFECT_INT reduces skill rust by 10% per level above 8 */
3413 int ret = ( ( rate_option == "vanilla" || rate_option == "capped" ) ?
3414 100 : 100 + 10 * ( intel - 8 ) );
3415
3416 ret *= mutation_value( "skill_rust_multiplier" );
3417
3418 if( ret < 0 ) {
3419 ret = 0;
3420 }
3421
3422 return ret;
3423}

References get_int(), mutation_value(), and cata::hash64_detail::ret.

Referenced by do_skill_rust(), draw_stats_info(), and set_stats().

◆ scored_crit()

bool Character::scored_crit ( float  target_dodge,
const item weap 
) const

Returns true if the player scores a critical hit.

Definition at line 728 of file melee.cpp.

729{
730 return rng_float( 0, 1.0 ) < crit_chance( hit_roll(), target_dodge, weap );
731}
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:741

References crit_chance(), hit_roll(), and rng_float().

Referenced by melee_attack().

◆ sees() [1/2]

bool Character::sees ( const Creature critter) const
overridevirtual

The functions check whether this creature can see the target.

The target may either be another creature (critter), or a specific point on the map.

The function that take another creature as input should check visibility of that creature (e.g. not digging, or otherwise invisible). They must than check whether the location of the other monster is visible.

Reimplemented from Creature.

Definition at line 10442 of file character.cpp.

10443{
10444 // This handles only the player/npc specific stuff (monsters don't have traits or bionics).
10445 const int dist = rl_dist( pos(), critter.pos() );
10446 if( dist <= 3 && has_active_mutation( trait_ANTENNAE ) ) {
10447 return true;
10448 }
10449
10450 return Creature::sees( critter );
10451}
virtual bool sees(const Creature &critter) const
The functions check whether this creature can see the target.
Definition: creature.cpp:202

References has_active_mutation(), Creature::pos(), pos(), rl_dist(), Creature::sees(), and trait_ANTENNAE.

◆ sees() [2/2]

bool Character::sees ( const tripoint t,
bool  is_player = false,
int  range_mod = 0 
) const
overridevirtual

Reimplemented from Creature.

Definition at line 10425 of file character.cpp.

10426{
10427 const int wanted_range = rl_dist( pos(), t );
10428 bool can_see = is_player() ? get_map().pl_sees( t, wanted_range ) :
10429 Creature::sees( t );
10430 // Clairvoyance is now pretty cheap, so we can check it early
10431 if( wanted_range < MAX_CLAIRVOYANCE && wanted_range < clairvoyance() ) {
10432 return true;
10433 }
10434
10435 if( can_see && wanted_range > unimpaired_range() ) {
10436 can_see = false;
10437 }
10438
10439 return can_see;
10440}
int unimpaired_range() const
Returns the player maximum vision range factoring in mutations, diseases, and other effects.
Definition: character.cpp:743
int clairvoyance() const
Returns the distance the player can see through walls.
Definition: character.cpp:802
bool pl_sees(const tripoint &t, int max_range) const
Whether the player character (g->u) can see the given square (local map coordinates).
Definition: lightmap.cpp:748

References clairvoyance(), get_map(), Creature::is_player(), MAX_CLAIRVOYANCE, map::pl_sees(), pos(), rl_dist(), Creature::sees(), and unimpaired_range().

Referenced by npc::address_needs(), npc::address_player(), grid_furn_transform_queue::apply(), npc::assess_danger(), bionics_uninstall_failure(), calculate_aim_cap(), game::catch_a_monster(), game::chat(), check_mount_will_move(), npc::check_or_use_weapon_cbm(), npc::complain(), npc::do_reload(), draw_critter_internal(), game::draw_line(), game::draw_look_around_cursor(), draw_throw_aim(), npc::drop_items(), explosion_handler::emp_blast(), npc::enough_time_to_reload(), npc::execute_action(), game::extended_description(), npc::find_corpse_to_pulp(), npc::find_item(), game::find_nearby_items(), heal_actor::finish_using(), game::fling_creature(), npc::follow_distance(), game::forced_door_closing(), fungal_effects::fungalize(), generic_multi_activity_check_requirement(), get_hostile_creatures(), get_path_avoid(), game::get_player_input(), get_visible_creatures(), game::handle_action(), npc::handle_sound(), vehicle::handle_trap(), npc::heal_player(), npc::heal_self(), talk_function::hostile(), avatar::invoke_item(), is_visible_in_range(), mdeath::jabberwock(), game::knockback(), target_ui::list_friendlies_in_lof(), game::list_items(), game::look_around(), npc::method_of_attack(), npc::move(), npc::mug_player(), iuse::note_bionics(), target_ui::panel_target_info(), npc::pick_up_item(), pl_sees(), npc::pretend_heal(), game::print_creature_info(), npc::print_info(), sounds::process_sound_markers(), npc::reach_omt_destination(), npc::regen_ai_cache(), iuse::robotcontrol(), player::search_surroundings(), npc::see_item_say_smth(), activity_handlers::spellcasting_finish(), fungal_effects::spread_fungus_one_tile(), suffer_from_schizophrenia(), game::try_get_right_click_action(), game::update_stair_monsters(), editmap::update_view_with_help(), countdown_actor::use(), and npc::use_painkiller().

◆ sees_with_infrared()

bool Character::sees_with_infrared ( const Creature critter) const

Check whether the this player can see the other creature with infrared.

This implies this player can see infrared and the target is visible with infrared (is warm). And of course a line of sight exists.

Definition at line 10214 of file character.cpp.

10215{
10216 if( !vision_mode_cache[IR_VISION] || !critter.is_warm() ) {
10217 return false;
10218 }
10219
10220 map &here = get_map();
10221 if( is_player() || critter.is_player() ) {
10222 // Players should not use map::sees
10223 // Likewise, players should not be "looked at" with map::sees, not to break symmetry
10224 return here.pl_line_of_sight( critter.pos(),
10226 }
10227
10228 return here.sees( pos(), critter.pos(), sight_range( current_daylight_level( calendar::turn ) ) );
10229}
double current_daylight_level(const time_point &p)
Returns the current seasonally-adjusted maximum daylight level.
Definition: calendar.cpp:171
bool sees(const tripoint &F, const tripoint &T, int range) const
Returns whether F sees T with a view range of range.
Definition: map.cpp:6112
bool pl_line_of_sight(const tripoint &t, int max_range) const
Uses the map cache to tell if the player could see the given square.
Definition: lightmap.cpp:766

References current_daylight_level(), get_map(), IR_VISION, Creature::is_player(), Creature::is_warm(), map::pl_line_of_sight(), Creature::pos(), pos(), map::sees(), sight_range(), calendar::turn, and vision_mode_cache.

Referenced by calculate_aim_cap(), draw_critter_internal(), target_ui::panel_target_info(), pl_sees(), and game::print_all_tile_info().

◆ sees_with_specials()

bool Character::sees_with_specials ( const Creature critter) const

Definition at line 6440 of file character.cpp.

6441{
6442 // electroreceptors grants vision of robots and electric monsters through walls
6444 ( critter.in_species( ROBOT ) || critter.has_flag( MF_ELECTRIC ) ) ) {
6445 return true;
6446 }
6447
6448 if( critter.digging() && has_active_bionic( bio_ground_sonar ) ) {
6449 // Bypass the check below, the bionic sonar also bypasses the sees(point) check because
6450 // walls don't block sonar which is transmitted in the ground, not the air.
6451 // TODO: this might need checks whether the player is in the air, or otherwise not connected
6452 // to the ground. It also might need a range check.
6453 return true;
6454 }
6455
6456 return false;
6457}
static const trait_id trait_ELECTRORECEPTORS("ELECTRORECEPTORS")
static const species_id ROBOT("ROBOT")
static const bionic_id bio_ground_sonar("bio_ground_sonar")
virtual bool digging() const
Definition: creature.cpp:179
@ MF_ELECTRIC
Definition: mtype.h:95

References bio_ground_sonar, Creature::digging(), has_active_bionic(), Creature::has_flag(), has_trait(), Creature::in_species(), MF_ELECTRIC, ROBOT, and trait_ELECTRORECEPTORS.

Referenced by draw_critter_internal(), target_ui::panel_target_info(), pl_sees(), and game::print_all_tile_info().

◆ set_base_age()

void Character::set_base_age ( int  age)

Definition at line 6905 of file character.cpp.

6906{
6907 init_age = age;
6908}

References age(), and init_age.

Referenced by debug_menu::character_edit_menu(), and set_description().

◆ set_base_height()

void Character::set_base_height ( int  height)

Definition at line 6934 of file character.cpp.

6935{
6937}

References height(), and init_height.

Referenced by debug_menu::character_edit_menu(), and set_description().

◆ set_check_encumbrance()

void Character::set_check_encumbrance ( bool  new_check)
inline

Definition at line 1949 of file character.h.

1949 {
1950 check_encumbrance = new_check;
1951 }

References check_encumbrance.

◆ set_destination()

void Character::set_destination ( const std::vector< tripoint > &  route,
const player_activity new_destination_activity = player_activity() 
)

◆ set_destination_activity()

void Character::set_destination_activity ( const player_activity new_destination_activity)

Definition at line 1018 of file character.cpp.

1019{
1020 destination_activity = new_destination_activity;
1021}

References destination_activity.

Referenced by set_destination().

◆ set_dex_bonus()

void Character::set_dex_bonus ( int  ndex)
virtual

Definition at line 4175 of file character.cpp.

4176{
4177 dex_bonus = ndex;
4178 dex_cur = std::max( 0, dex_max + dex_bonus );
4179}

References dex_bonus, dex_cur, and dex_max.

◆ set_fac_id()

void Character::set_fac_id ( const std::string &  my_fac_id)

Definition at line 7893 of file character.cpp.

7894{
7895 fac_id = faction_id( my_fac_id );
7896}
faction_id fac_id
Definition: character.h:2129
string_id< faction > faction_id
Definition: clzones.h:30

References fac_id.

Referenced by npc_template::load().

◆ set_fatigue()

void Character::set_fatigue ( int  nfatigue)
virtual

Definition at line 4456 of file character.cpp.

4457{
4458 nfatigue = std::max( nfatigue, 0 );
4459 if( fatigue != nfatigue ) {
4460 fatigue = nfatigue;
4461 on_stat_change( "fatigue", fatigue );
4462 }
4463}

References fatigue, and on_stat_change().

Referenced by npc::address_needs(), debug_menu::character_edit_menu(), check_needs_extremes(), player::environmental_revert_effect(), basecamp::finish_return(), player::hardcoded_effects(), mod_fatigue(), and update_needs().

◆ set_healthy()

void Character::set_healthy ( int  nhealthy)
virtual

Setters for health values exclusive to characters.

Definition at line 4258 of file character.cpp.

4259{
4260 healthy = nhealthy;
4261}

References healthy.

Referenced by debug_menu::character_edit_menu(), and player::environmental_revert_effect().

◆ set_healthy_mod()

void Character::set_healthy_mod ( int  nhealthy_mod)
virtual

Definition at line 4270 of file character.cpp.

4271{
4272 healthy_mod = nhealthy_mod;
4273}

References healthy_mod.

Referenced by debug_menu::character_edit_menu(), player::environmental_revert_effect(), suffer_from_radiation(), update_health(), and vomit().

◆ set_highest_cat_level()

void Character::set_highest_cat_level ( )

Recalculates mutation_category_level[] values for the player.

Definition at line 7937 of file character.cpp.

7938{
7940
7941 // For each of our mutations...
7942 for( const trait_id &mut : get_mutations() ) {
7943 // ...build up a map of all prerequisite/replacement mutations along the tree, along with their distance from the current mutation
7944 std::unordered_map<trait_id, int> dependency_map;
7945 build_mut_dependency_map( mut, dependency_map, 0 );
7946
7947 // Then use the map to set the category levels
7948 for( const std::pair<const trait_id, int> &i : dependency_map ) {
7949 const mutation_branch &mdata = i.first.obj();
7950 if( !mdata.flags.count( "NON_THRESH" ) ) {
7951 for( const std::string &cat : mdata.category ) {
7952 // Decay category strength based on how far it is from the current mutation
7953 mutation_category_level[cat] += 8 / static_cast<int>( std::pow( 2, i.second ) );
7954 }
7955 }
7956 }
7957 }
7958}

References build_mut_dependency_map(), mutation_branch::category, mutation_branch::flags, get_mutations(), and mutation_category_level.

Referenced by avatar::load(), mutate_towards(), remove_mutation(), and game::start_game().

◆ set_int_bonus()

void Character::set_int_bonus ( int  nint)
virtual

Definition at line 4185 of file character.cpp.

4186{
4187 int_bonus = nint;
4188 int_cur = std::max( 0, int_max + int_bonus );
4189}

References int_bonus, int_cur, and int_max.

◆ set_max_power_level()

void Character::set_max_power_level ( const units::energy npower_max)

Definition at line 1985 of file character.cpp.

1986{
1987 max_power_level = npower_max;
1988}

References max_power_level.

Referenced by bionics_install_failure(), and player::player().

◆ set_movement_mode()

virtual void Character::set_movement_mode ( character_movemode  mode)
pure virtual

Implemented in avatar, and npc.

Referenced by dismount(), and forced_dismount().

◆ set_mutation()

◆ set_painkiller()

void Character::set_painkiller ( int  npkill)

Sets intensity of painkillers

Definition at line 9802 of file character.cpp.

9803{
9804 npkill = std::max( npkill, 0 );
9805 if( pkill != npkill ) {
9806 const int prev_pain = get_perceived_pain();
9807 pkill = npkill;
9808 on_stat_change( "pkill", pkill );
9809 const int cur_pain = get_perceived_pain();
9810
9811 if( cur_pain != prev_pain ) {
9812 react_to_felt_pain( cur_pain - prev_pain );
9813 on_stat_change( "perceived_pain", cur_pain );
9814 }
9815 }
9816}
void react_to_felt_pain(int intensity)
Definition: character.cpp:853

References Creature::get_perceived_pain(), on_stat_change(), pkill, and react_to_felt_pain().

Referenced by activate_bionic(), player::environmental_revert_effect(), mod_painkiller(), iuse::smoking(), and iuse::weed_cake().

◆ set_per_bonus()

void Character::set_per_bonus ( int  nper)
virtual

Definition at line 4180 of file character.cpp.

4181{
4182 per_bonus = nper;
4183 per_cur = std::max( 0, per_max + per_bonus );
4184}

References per_bonus, per_cur, and per_max.

◆ set_power_level()

void Character::set_power_level ( const units::energy npower)

Definition at line 1980 of file character.cpp.

1981{
1982 power_level = std::min( npower, max_power_level );
1983}

References max_power_level, and power_level.

Referenced by activate_bionic(), avatar::create(), mod_power_level(), and player::player().

◆ set_rad()

void Character::set_rad ( int  new_rad)

◆ set_skill_level()

void Character::set_skill_level ( const skill_id ident,
int  level 
)

◆ set_sleep_deprivation()

void Character::set_sleep_deprivation ( int  nsleep_deprivation)
virtual

Definition at line 4465 of file character.cpp.

4466{
4467 sleep_deprivation = std::min( static_cast< int >( sleep_deprivation_levels::massive ), std::max( 0,
4468 nsleep_deprivation ) );
4469}

References massive, and sleep_deprivation.

Referenced by debug_menu::character_edit_menu(), player::environmental_revert_effect(), basecamp::finish_return(), mod_sleep_deprivation(), and update_needs().

◆ set_stamina()

◆ set_stashed_activity()

void Character::set_stashed_activity ( const player_activity act,
const player_activity act_back = player_activity() 
)

Definition at line 978 of file character.cpp.

979{
981 stashed_outbounds_backlog = act_back;
982}

References act, stashed_outbounds_activity, and stashed_outbounds_backlog.

◆ set_stim()

void Character::set_stim ( int  new_stim)

Definition at line 7180 of file character.cpp.

7181{
7182 stim = new_stim;
7183}

References stim.

Referenced by activate_bionic(), player::environmental_revert_effect(), modify_stimulation(), and update_needs().

◆ set_stored_kcal()

void Character::set_stored_kcal ( int  kcal)
virtual

Setters for need values exclusive to characters.

Definition at line 4326 of file character.cpp.

4327{
4328 if( stored_calories != kcal ) {
4329 stored_calories = std::min( kcal, max_stored_kcal() );
4330 }
4331}

References max_stored_kcal(), and stored_calories.

Referenced by debug_menu::character_edit_menu(), npc::consume_food(), avatar::create(), player::environmental_revert_effect(), marloss_common(), mod_stored_kcal(), and update_stomach().

◆ set_str_bonus()

void Character::set_str_bonus ( int  nstr)
virtual

Setters for stats exclusive to characters.

Definition at line 4170 of file character.cpp.

4171{
4172 str_bonus = nstr;
4173 str_cur = std::max( 0, str_max + str_bonus );
4174}

References str_bonus, str_cur, and str_max.

◆ set_thirst()

void Character::set_thirst ( int  nthirst)
virtual

Definition at line 4438 of file character.cpp.

4439{
4440 if( thirst != nthirst ) {
4441 thirst = nthirst;
4442 on_stat_change( "thirst", thirst );
4443 }
4444}

References on_stat_change(), and thirst.

Referenced by debug_menu::character_edit_menu(), npc::consume_food(), npc::consume_food_from_camp(), player::environmental_revert_effect(), basecamp::finish_return(), mod_thirst(), update_stomach(), and vomit().

◆ set_time_died()

void Character::set_time_died ( const time_point time)
inline

set the turn the turn the character died if not already done

Definition at line 1414 of file character.h.

1414 {
1416 time_died = time;
1417 }
1418 }

References calendar::before_time_starts, and time_died.

Referenced by die().

◆ set_type_of_scent()

void Character::set_type_of_scent ( const scenttype_id id)

Definition at line 8768 of file character.cpp.

8769{
8770 type_of_scent = id;
8771}

References id, and type_of_scent.

Referenced by restore_scent(), update_type_of_scent(), and change_scent_iuse::use().

◆ setID()

void Character::setID ( character_id  i,
bool  force = false 
)

Definition at line 466 of file character.cpp.

467{
468 if( id.is_valid() && !force ) {
469 debugmsg( "tried to set id of a npc/player, but has already a id: %d", id.get_value() );
470 } else if( !i.is_valid() && !force ) {
471 debugmsg( "tried to set invalid id of a npc/player: %d", i.get_value() );
472 } else {
473 id = i;
474 }
475}
bool is_valid() const
Definition: character_id.h:19
int get_value() const
Definition: character_id.h:23

References debugmsg, character_id::get_value(), Creature::get_value(), and character_id::is_valid().

Referenced by player::load(), game::load(), npc::randomize(), and game::start_game().

◆ setpos()

◆ setx()

void Character::setx ( int  x)
inline

◆ sety()

void Character::sety ( int  y)
inline

◆ setz()

void Character::setz ( int  z)
inline

Definition at line 796 of file character.h.

796 {
797 setpos( tripoint( position.xy(), z ) );
798 }

References position, setpos(), and tripoint::xy().

Referenced by start_location::place_player(), and game::vertical_shift().

◆ shift_destination()

void Character::shift_destination ( const point shift)

Definition at line 10351 of file character.cpp.

10352{
10354 *next_expected_position += shift;
10355 }
10356
10357 for( auto &elem : auto_move_route ) {
10358 elem += shift;
10359 }
10360}

References auto_move_route, and next_expected_position.

Referenced by game::update_map().

◆ shoe_type_count()

int Character::shoe_type_count ( const itype_id it) const

Returns 1 if the player is wearing an item of that count on one foot, 2 if on both, and zero if on neither.

Definition at line 8961 of file character.cpp.

8962{
8963 int ret = 0;
8964 if( is_wearing_on_bp( it, bodypart_id( "foot_l" ) ) ) {
8965 ret++;
8966 }
8967 if( is_wearing_on_bp( it, bodypart_id( "foot_r" ) ) ) {
8968 ret++;
8969 }
8970 return ret;
8971}
bool is_wearing_on_bp(const itype_id &it, const bodypart_id &bp) const
Returns true if the player is wearing the item on the given body part.
Definition: character.cpp:3263

References is_wearing_on_bp(), and cata::hash64_detail::ret.

Referenced by avatar_action::swim(), and game::vertical_move().

◆ short_description()

std::string Character::short_description ( ) const

Definition at line 10340 of file character.cpp.

10341{
10342 return join( short_description_parts(), "; " );
10343}
std::vector< std::string > short_description_parts() const
arg_join< It, Sentinel, char > join(It begin, Sentinel end, string_view sep)
Returns an object that formats the iterator range [begin, end) with elements separated by sep.

References join(), and short_description_parts().

◆ short_description_parts()

std::vector< std::string > Character::short_description_parts ( ) const

Definition at line 10316 of file character.cpp.

10317{
10318 std::vector<std::string> result;
10319
10320 std::string gender = male ? _( "male" ) : _( "female" );
10321 result.push_back( name + ", " + gender );
10322 if( is_armed() ) {
10323 result.push_back( _( "Wielding: " ) + weapon.tname() );
10324 }
10325 const std::string worn_str = enumerate_as_string( worn.begin(), worn.end(),
10326 []( const item & it ) {
10327 return it.tname();
10328 } );
10329 if( !worn_str.empty() ) {
10330 result.push_back( _( "Wearing: " ) + worn_str );
10331 }
10332 const int visibility_cap = 0; // no cap
10333 const auto trait_str = visible_mutations( visibility_cap );
10334 if( !trait_str.empty() ) {
10335 result.push_back( _( "Traits: " ) + trait_str );
10336 }
10337 return result;
10338}
std::string visible_mutations(int visibility_cap) const
Returns an enumeration of visible mutations with colors.
Definition: mutation.cpp:1753

References _, enumerate_as_string(), is_armed(), male, name, item::tname(), visible_mutations(), weapon, and worn.

Referenced by short_description().

◆ shout()

void Character::shout ( std::string  msg = "",
bool  order = false 
)

Definition at line 7743 of file character.cpp.

7744{
7745 int base = 10;
7746 std::string shout;
7747
7748 // You can't shout without your face
7749 if( has_trait( trait_PROF_FOODP ) && !( is_wearing( itype_id( "foodperson_mask" ) ) ||
7750 is_wearing( itype_id( "foodperson_mask_on" ) ) ) ) {
7751 add_msg_if_player( m_warning, _( "You try to shout but you have no face!" ) );
7752 return;
7753 }
7754
7755 // Mutations make shouting louder, they also define the default message
7756 if( has_trait( trait_SHOUT3 ) ) {
7757 base = 20;
7758 if( msg.empty() ) {
7759 msg = is_player() ? _( "yourself let out a piercing howl!" ) : _( "a piercing howl!" );
7760 shout = "howl";
7761 }
7762 } else if( has_trait( trait_SHOUT2 ) ) {
7763 base = 15;
7764 if( msg.empty() ) {
7765 msg = is_player() ? _( "yourself scream loudly!" ) : _( "a loud scream!" );
7766 shout = "scream";
7767 }
7768 }
7769
7770 if( msg.empty() ) {
7771 msg = is_player() ? _( "yourself shout loudly!" ) : _( "a loud shout!" );
7772 shout = "default";
7773 }
7774 int noise = get_shout_volume();
7775
7776 // Minimum noise volume possible after all reductions.
7777 // Volume 1 can't be heard even by player
7778 constexpr int minimum_noise = 2;
7779
7780 if( noise <= base ) {
7781 std::string dampened_shout;
7782 std::transform( msg.begin(), msg.end(), std::back_inserter( dampened_shout ), tolower );
7783 msg = std::move( dampened_shout );
7784 }
7785
7786 // Screaming underwater is not good for oxygen and harder to do overall
7787 if( underwater ) {
7789 mod_stat( "oxygen", -noise );
7790 }
7791 }
7792
7793 const int penalty = encumb( bp_mouth ) * 3 / 2;
7794 // TODO: indistinct noise descriptions should be handled in the sounds code
7795 if( noise <= minimum_noise ) {
7797 _( "The sound of your voice is almost completely muffled!" ) );
7798 msg = is_player() ? _( "your muffled shout" ) : _( "an indistinct voice" );
7799 } else if( noise * 2 <= noise + penalty ) {
7800 // The shout's volume is 1/2 or lower of what it would be without the penalty
7801 add_msg_if_player( m_warning, _( "The sound of your voice is significantly muffled!" ) );
7802 }
7803
7805 "shout", shout );
7806}
static const trait_id trait_GILLS_CEPH("GILLS_CEPH")
static const trait_id trait_GILLS("GILLS")
void shout(std::string msg="", bool order=false)
Definition: character.cpp:7743
int get_shout_volume() const
Definition: character.cpp:7700
bool move(avatar &you, map &m, const tripoint &d)
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1589

References _, Creature::add_msg_if_player(), sounds::alert, bp_mouth, encumb(), get_shout_volume(), has_trait(), Creature::is_player(), is_wearing(), itype_id, m_warning, mod_stat(), avatar_action::move(), noise, sounds::order, pos(), shout(), sounds::sound(), trait_GILLS, trait_GILLS_CEPH, trait_PROF_FOODP, trait_SHOUT2, trait_SHOUT3, iexamine::transform(), and Creature::underwater.

Referenced by game::chat(), dialogue::dynamic_line(), shout(), suffer_from_schizophrenia(), and suffer_while_awake().

◆ sight_impaired()

bool Character::sight_impaired ( ) const

◆ sight_range()

int Character::sight_range ( int  light_level) const
overridevirtual

Returns the player's sight range.

Implements Creature.

Definition at line 719 of file character.cpp.

720{
721 if( light_level == 0 ) {
722 return 1;
723 }
724 /* Via Beer-Lambert we have:
725 * light_level * (1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance) ) <= LIGHT_AMBIENT_LOW
726 * Solving for distance:
727 * 1 / exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) <= LIGHT_AMBIENT_LOW / light_level
728 * 1 <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW / light_level
729 * light_level <= exp( LIGHT_TRANSPARENCY_OPEN_AIR * distance ) * LIGHT_AMBIENT_LOW
730 * log(light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance + log(LIGHT_AMBIENT_LOW)
731 * log(light_level) - log(LIGHT_AMBIENT_LOW) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance
732 * log(LIGHT_AMBIENT_LOW / light_level) <= LIGHT_TRANSPARENCY_OPEN_AIR * distance
733 * log(LIGHT_AMBIENT_LOW / light_level) * (1 / LIGHT_TRANSPARENCY_OPEN_AIR) <= distance
734 */
735 int range = static_cast<int>( -std::log( get_vision_threshold( static_cast<int>
736 ( get_map().ambient_light_at( pos() ) ) ) / static_cast<float>( light_level ) ) *
737 ( 1.0 / LIGHT_TRANSPARENCY_OPEN_AIR ) );
738
739 // Clamp to [1, sight_max].
740 return clamp( range, 1, sight_max );
741}
float get_vision_threshold(float light_level) const
Returns the apparent light level at which the player can see.
Definition: character.cpp:1812
static constexpr float LIGHT_TRANSPARENCY_OPEN_AIR
Definition: lightmap.h:36

References clamp(), get_map(), get_vision_threshold(), LIGHT_TRANSPARENCY_OPEN_AIR, pos(), and sight_max.

Referenced by game::calc_driving_offset(), overmap_sight_range(), sees_with_infrared(), and editmap::update_view_with_help().

◆ skin_name()

std::string Character::skin_name ( ) const
overridevirtual

Returns the name of the player's outer layer, e.g.

"armor plates"

Implements Creature.

Definition at line 561 of file character.cpp.

562{
563 // TODO: Return actual deflecting layer name
564 return _( "armor" );
565}

References _.

◆ sound_hallu()

void Character::sound_hallu ( )

Creates an auditory hallucination.

Definition at line 1706 of file suffer.cpp.

1707{
1708 // Random 'dangerous' sound from a random direction
1709 // 1/5 chance to be a loud sound
1710 std::vector<std::string> dir{ "north",
1711 "northeast",
1712 "northwest",
1713 "south",
1714 "southeast",
1715 "southwest",
1716 "east",
1717 "west" };
1718
1719 std::vector<std::string> dirz{ "and above you ", "and below you " };
1720
1721 std::vector<std::tuple<std::string, std::string, std::string>> desc{
1722 std::make_tuple( "whump!", "smash_fail", "t_door_c" ),
1723 std::make_tuple( "crash!", "smash_success", "t_door_c" ),
1724 std::make_tuple( "glass breaking!", "smash_success", "t_window_domestic" ) };
1725
1726 std::vector<std::tuple<std::string, std::string, std::string>> desc_big{
1727 std::make_tuple( "huge explosion!", "explosion", "default" ),
1728 std::make_tuple( "bang!", "fire_gun", "glock_19" ),
1729 std::make_tuple( "blam!", "fire_gun", "mossberg_500" ),
1730 std::make_tuple( "crash!", "smash_success", "t_wall" ),
1731 std::make_tuple( "SMASH!", "smash_success", "t_wall" ) };
1732
1733 std::string i_dir = dir[rng( 0, dir.size() - 1 )];
1734
1735 if( one_in( 10 ) ) {
1736 i_dir += " " + dirz[rng( 0, dirz.size() - 1 )];
1737 }
1738
1739 std::string i_desc;
1740 std::pair<std::string, std::string> i_sound;
1741 if( one_in( 5 ) ) {
1742 int r_int = rng( 0, desc_big.size() - 1 );
1743 i_desc = std::get<0>( desc_big[r_int] );
1744 i_sound = std::make_pair( std::get<1>( desc_big[r_int] ), std::get<2>( desc_big[r_int] ) );
1745 } else {
1746 int r_int = rng( 0, desc.size() - 1 );
1747 i_desc = std::get<0>( desc[r_int] );
1748 i_sound = std::make_pair( std::get<1>( desc[r_int] ), std::get<2>( desc[r_int] ) );
1749 }
1750
1751 add_msg( m_warning, _( "From the %1$s you hear %2$s" ), i_dir, i_desc );
1752 sfx::play_variant_sound( i_sound.first, i_sound.second, rng( 20, 80 ) );
1753}
void play_variant_sound(const std::string &id, const std::string &variant, int volume, units::angle angle, double pitch_min=-1.0, double pitch_max=-1.0)
Definition: sounds.cpp:1599

References _, add_msg(), m_warning, one_in(), sfx::play_variant_sound(), and rng().

Referenced by player::hardcoded_effects(), and suffer_from_schizophrenia().

◆ speed_rating()

float Character::speed_rating ( ) const
overridevirtual

Returns an approximate number of tiles this creature can travel per turn.

Implements Creature.

Reimplemented in npc.

Definition at line 10004 of file character.cpp.

10005{
10006 float ret = get_speed() / 100.0f;
10007 ret *= 100.0f / run_cost( 100, false );
10008 // Adjustment for player being able to run, but not doing so at the moment
10009 if( move_mode != CMM_RUN ) {
10010 ret *= 1.0f + ( static_cast<float>( get_stamina() ) / static_cast<float>( get_stamina_max() ) );
10011 }
10012 return ret;
10013}
int run_cost(int base_cost, bool diag=false) const
Returns the player's modified base movement cost.
int get_speed() const override
Definition: character.cpp:4140

References CMM_RUN, get_speed(), get_stamina(), get_stamina_max(), move_mode, cata::hash64_detail::ret, and run_cost().

◆ spores()

void Character::spores ( )

Definition at line 8790 of file character.cpp.

8791{
8792 map &here = get_map();
8793 fungal_effects fe( *g, here );
8794 //~spore-release sound
8795 sounds::sound( pos(), 10, sounds::sound_t::combat, _( "Pouf!" ), false, "misc", "puff" );
8796 for( const tripoint &sporep : here.points_in_radius( pos(), 1 ) ) {
8797 if( sporep == pos() ) {
8798 continue;
8799 }
8800 fe.fungalize( sporep, this, 0.25 );
8801 }
8802}

References _, sounds::combat, fungal_effects::fungalize(), g, get_map(), map::points_in_radius(), pos(), and sounds::sound().

Referenced by activate_mutation(), player::hardcoded_effects(), and suffer_while_awake().

◆ stamina_move_cost_modifier()

float Character::stamina_move_cost_modifier ( ) const

Definition at line 7271 of file character.cpp.

7272{
7273 // Both walk and run speed drop to half their maximums as stamina approaches 0.
7274 // Convert stamina to a float first to allow for decimal place carrying
7275 float stamina_modifier = ( static_cast<float>( get_stamina() ) / get_stamina_max() + 1 ) / 2;
7276 if( move_mode == CMM_RUN && get_stamina() >= 0 ) {
7277 // Rationale: Average running speed is 2x walking speed. (NOT sprinting)
7278 stamina_modifier *= 2.0;
7279 }
7280 if( move_mode == CMM_CROUCH ) {
7281 stamina_modifier *= 0.5;
7282 }
7283 return stamina_modifier;
7284}
@ CMM_CROUCH
Definition: character.h:103

References CMM_CROUCH, CMM_RUN, get_stamina(), get_stamina_max(), and move_mode.

Referenced by burn_move_stamina(), and run_cost().

◆ start_destination_activity()

void Character::start_destination_activity ( )

Definition at line 10514 of file character.cpp.

10515{
10516 if( !has_destination_activity() ) {
10517 debugmsg( "Tried to start invalid destination activity" );
10518 return;
10519 }
10520
10523}
void clear_destination()
bool has_destination_activity() const

References assign_activity(), clear_destination(), debugmsg, get_destination_activity(), and has_destination_activity().

Referenced by game::handle_action(), and npc::move().

◆ start_hauling()

void Character::start_hauling ( )

Definition at line 9180 of file character.cpp.

9181{
9182 add_msg( _( "You start hauling items along the ground." ) );
9183 if( is_armed() ) {
9184 add_msg( m_warning, _( "Your hands are not free, which makes hauling slower." ) );
9185 }
9186 hauling = true;
9187}

References _, add_msg(), hauling, is_armed(), and m_warning.

Referenced by haul().

◆ stop_hauling()

void Character::stop_hauling ( )

Definition at line 9189 of file character.cpp.

9190{
9191 add_msg( _( "You stop hauling items." ) );
9192 hauling = false;
9193 if( has_activity( ACT_MOVE_ITEMS ) ) {
9195 }
9196}

References _, ACT_MOVE_ITEMS, add_msg(), cancel_activity(), has_activity(), and hauling.

Referenced by cancel_activity(), haul(), game::place_player(), avatar::set_movement_mode(), and game::vertical_move().

◆ store()

void Character::store ( JsonOut json) const
protected

Load variables from json into object.

These variables are common to both the avatar and NPCs.

Definition at line 645 of file savegame_json.cpp.

646{
647 Creature::store( json );
648
649 // assumes already in Character object
650 // positional data
651 json.member( "posx", position.x );
652 json.member( "posy", position.y );
653 json.member( "posz", position.z );
654
655 // stat
656 json.member( "str_cur", str_cur );
657 json.member( "str_max", str_max );
658 json.member( "dex_cur", dex_cur );
659 json.member( "dex_max", dex_max );
660 json.member( "int_cur", int_cur );
661 json.member( "int_max", int_max );
662 json.member( "per_cur", per_cur );
663 json.member( "per_max", per_max );
664
665 json.member( "str_bonus", str_bonus );
666 json.member( "dex_bonus", dex_bonus );
667 json.member( "per_bonus", per_bonus );
668 json.member( "int_bonus", int_bonus );
669
670 json.member( "base_age", init_age );
671 json.member( "base_height", init_height );
672
673 if( prof.is_valid() ) {
674 json.member( "profession", prof );
675 }
676 json.member( "custom_profession", custom_profession );
677
678 // health
679 json.member( "healthy", healthy );
680 json.member( "healthy_mod", healthy_mod );
681 json.member( "healed_24h", healed_total );
682
683 // status
684 json.member( "temp_cur", temp_cur );
685 json.member( "temp_conv", temp_conv );
686 json.member( "frostbite_timer", frostbite_timer );
687 json.member( "body_wetness", body_wetness );
688
689 // needs
690 json.member( "thirst", thirst );
691 json.member( "fatigue", fatigue );
692 json.member( "sleep_deprivation", sleep_deprivation );
693 json.member( "stored_calories", stored_calories );
694 json.member( "radiation", radiation );
695 json.member( "stamina", stamina );
696 json.member( "vitamin_levels", vitamin_levels );
697 json.member( "pkill", pkill );
698 json.member( "omt_path", omt_path );
699 json.member( "consumption_history", consumption_history );
700
701 // crafting etc
702 json.member( "destination_activity", destination_activity );
703 json.member( "activity", activity );
704 json.member( "stashed_outbounds_activity", stashed_outbounds_activity );
705 json.member( "stashed_outbounds_backlog", stashed_outbounds_backlog );
706 json.member( "backlog", backlog );
707 json.member( "activity_vehicle_part_index", activity_vehicle_part_index ); // NPC activity
708
709 // handling for storing activity requirements
710 if( !backlog.empty() && !backlog.front().str_values.empty() && ( ( activity &&
711 activity.id() == activity_id( "ACT_FETCH_REQUIRED" ) ) || ( destination_activity &&
712 destination_activity.id() == activity_id( "ACT_FETCH_REQUIRED" ) ) ) ) {
713 requirement_data things_to_fetch = requirement_id( backlog.front().str_values.back() ).obj();
714 json.member( "fetch_data", things_to_fetch );
715 }
716
717 json.member( "stim", stim );
718 json.member( "type_of_scent", type_of_scent );
719
720 // breathing
721 json.member( "underwater", underwater );
722 json.member( "oxygen", oxygen );
723
724 // traits: permanent 'mutations' more or less
725 json.member( "traits", my_traits );
726 json.member( "mutations", my_mutations );
727 json.member( "magic", magic );
728 json.member( "martial_arts_data", martial_arts_data );
729 // "Fracking Toasters" - Saul Tigh, toaster
730 json.member( "my_bionics", *my_bionics );
731
732 json.member_as_string( "move_mode", move_mode );
733
734 // storing the mount
735 if( is_mounted() ) {
736 json.member( "mounted_creature", g->critter_tracker->temporary_id( *mounted_creature ) );
737 }
738
739 morale->store( json );
740
741 // skills
742 json.member( "skills" );
743 json.start_object();
744 for( const auto &pair : *_skills ) {
745 json.member( pair.first.str(), pair.second );
746 }
747 json.end_object();
748
749 // npc; unimplemented
750 if( power_level < 1_kJ ) {
751 json.member( "power_level", std::to_string( units::to_joule( power_level ) ) + " J" );
752 } else {
753 json.member( "power_level", units::to_kilojoule( power_level ) );
754 }
755 json.member( "max_power_level", units::to_kilojoule( max_power_level ) );
756
757 if( !overmap_time.empty() ) {
758 json.member( "overmap_time" );
759 json.start_array();
760 for( const std::pair<const point_abs_omt, time_duration> &pr : overmap_time ) {
761 json.write( pr.first );
762 json.write( pr.second );
763 }
764 json.end_array();
765 }
766 json.member( "stomach", stomach );
767 json.member( "automoveroute", auto_move_route );
768 json.member( "known_traps" );
769 json.start_array();
770 for( const auto &elem : known_traps ) {
771 json.start_object();
772 json.member( "x", elem.first.x );
773 json.member( "y", elem.first.y );
774 json.member( "z", elem.first.z );
775 json.member( "trap", elem.second );
776 json.end_object();
777 }
778 json.end_array();
779}
void store(JsonOut &jsout) const
These two functions are responsible for storing and loading the members of this class to/from json da...
void member_as_string(const std::string &name, const T &value)
Definition: json.h:751
void end_array()
Definition: json.cpp:1961
void start_array(bool wrap=false)
Definition: json.cpp:1950
void start_object(bool wrap=false)
Definition: json.cpp:1931
void write(T val)
Definition: json.h:620
void end_object()
Definition: json.cpp:1942
void member(const std::string &name)
Definition: json.cpp:2046

References _skills, activity, activity_vehicle_part_index, auto_move_route, backlog, body_wetness, consumption_history, custom_profession, destination_activity, dex_bonus, dex_cur, dex_max, JsonOut::end_array(), JsonOut::end_object(), fatigue, frostbite_timer, g, healed_total, healthy, healthy_mod, player_activity::id(), init_age, init_height, int_bonus, int_cur, int_max, is_mounted(), string_id< T >::is_valid(), known_traps, magic, martial_arts_data, max_power_level, JsonOut::member(), JsonOut::member_as_string(), morale, mounted_creature, move_mode, my_bionics, my_mutations, my_traits, string_id< T >::obj(), omt_path, overmap_time, oxygen, per_bonus, per_cur, per_max, pkill, position, power_level, prof, radiation, sleep_deprivation, stamina, JsonOut::start_array(), JsonOut::start_object(), stashed_outbounds_activity, stashed_outbounds_backlog, stim, stomach, Creature::store(), stored_calories, str_bonus, str_cur, str_max, temp_conv, temp_cur, thirst, units::to_joule(), units::to_kilojoule(), to_string(), type_of_scent, Creature::underwater, vitamin_levels, JsonOut::write(), tripoint::x, tripoint::y, and tripoint::z.

Referenced by monster::serialize(), avatar::serialize(), npc::serialize(), and player::store().

◆ suffer()

void Character::suffer ( )

Handles a large number of timers decrementing and other randomized effects.

Definition at line 1467 of file suffer.cpp.

1468{
1469 const int current_stim = get_stim();
1470 // TODO: Remove this section and encapsulate hp_cur
1471 for( const std::pair<const bodypart_str_id, bodypart> &elem : get_body() ) {
1472 if( elem.second.get_hp_cur() <= 0 ) {
1473 add_effect( effect_disabled, 1_turns, elem.first->token );
1474 }
1475 }
1476
1477 for( size_t i = 0; i < get_bionics().size(); i++ ) {
1478 process_bionic( i );
1479 }
1480
1481 for( std::pair<const trait_id, Character::trait_data> &mut : my_mutations ) {
1482 const mutation_branch &mdata = mut.first.obj();
1483 if( calendar::once_every( 1_minutes ) ) {
1484 suffer_water_damage( mdata );
1485 }
1486 Character::trait_data &tdata = mut.second;
1487 if( tdata.powered ) {
1488 suffer_mutation_power( mdata, tdata );
1489 }
1490 }
1491
1492 if( underwater ) {
1494 }
1495
1497
1498 if( !in_sleep_state() ) {
1499 suffer_while_awake( current_stim );
1500 } // Done with while-awake-only effects
1501
1502 if( has_trait( trait_ASTHMA ) ) {
1503 suffer_from_asthma( current_stim );
1504 }
1505
1511 suffer_from_stimulants( current_stim );
1513 // Stimulants can lessen the PERCEIVED effects of sleep deprivation, but
1514 // they do nothing to cure it. As such, abuse is even more dangerous now.
1515 if( current_stim > 0 ) {
1516 // 100% of blacking out = 20160sd ; Max. stim modifier = 12500sd @ 250stim
1517 // Note: Very high stim already has its own slew of bad effects,
1518 // so the "useful" part of this bonus is actually lower.
1519 sleep_deprivation -= current_stim * 50;
1520 }
1521
1524 //Suffer from enchantments
1525 enchantment_cache->activate_passive( *this );
1526
1527 if( calendar::once_every( 1_hours ) ) {
1529 }
1530}
void suffer_in_sunlight()
Definition: suffer.cpp:714
void suffer_from_artifacts()
Definition: suffer.cpp:1312
void suffer_from_addictions()
Definition: suffer.cpp:273
void suffer_from_stimulants(int current_stim)
Definition: suffer.cpp:1334
void process_bionic(int b)
Handles bionic effects over time of the entered bionic.
Definition: bionics.cpp:1528
void suffer_water_damage(const mutation_branch &mdata)
suffer() subcalls
Definition: suffer.cpp:182
void suffer_from_pain()
Definition: suffer.cpp:1463
void suffer_while_awake(int current_stim)
Definition: suffer.cpp:300
void suffer_from_other_mutations()
Definition: suffer.cpp:941
void suffer_mutation_power(const mutation_branch &mdata, Character::trait_data &tdata)
Definition: suffer.cpp:202
void suffer_without_sleep(int sleep_deprivation)
Definition: suffer.cpp:1376
void suffer_while_underwater()
Definition: suffer.cpp:250
void suffer_from_bad_bionics()
Definition: suffer.cpp:1222
void suffer_from_radiation()
Definition: suffer.cpp:1049
void suffer_from_asthma(int current_stim)
Definition: suffer.cpp:613
bool powered
Whether the mutation is activated.
Definition: character.h:2044
static const efftype_id effect_accumulated_mutagen("accumulated_mutagen")
static const efftype_id effect_disabled("disabled")
static const trait_id trait_ASTHMA("ASTHMA")

References Creature::add_effect(), effect_accumulated_mutagen, effect_disabled, enchantment_cache, get_bionics(), Creature::get_body(), get_sleep_deprivation(), get_stim(), has_trait(), in_sleep_state(), my_mutations, num_bp, calendar::once_every(), Character::trait_data::powered, process_bionic(), sleep_deprivation, suffer_from_addictions(), suffer_from_artifacts(), suffer_from_asthma(), suffer_from_bad_bionics(), suffer_from_other_mutations(), suffer_from_pain(), suffer_from_radiation(), suffer_from_stimulants(), suffer_in_sunlight(), suffer_mutation_power(), suffer_water_damage(), suffer_while_awake(), suffer_while_underwater(), suffer_without_sleep(), trait_ASTHMA, and Creature::underwater.

Referenced by player::process_turn().

◆ suffer_from_addictions()

void Character::suffer_from_addictions ( )
private

Definition at line 273 of file suffer.cpp.

274{
275 time_duration timer = -6_hours;
276 if( has_trait( trait_ADDICTIVE ) ) {
277 timer = -10_hours;
278 } else if( has_trait( trait_NONADDICTIVE ) ) {
279 timer = -3_hours;
280 }
281 for( addiction &cur_addiction : addictions ) {
282 if( cur_addiction.sated <= 0_turns &&
283 cur_addiction.intensity >= MIN_ADDICTION_LEVEL ) {
284 addict_effect( *this, cur_addiction );
285 }
286 cur_addiction.sated -= 1_turns;
287 // Higher intensity addictions heal faster
288 if( cur_addiction.sated - 10_minutes * cur_addiction.intensity < timer ) {
289 if( cur_addiction.intensity <= 2 ) {
290 rem_addiction( cur_addiction.type );
291 break;
292 } else {
293 cur_addiction.intensity--;
294 cur_addiction.sated = 0_turns;
295 }
296 }
297 }
298}
void addict_effect(Character &u, addiction &add)
Definition: addiction.cpp:57
constexpr int MIN_ADDICTION_LEVEL
Definition: addiction.h:13
void rem_addiction(add_type type)
Removes an addition from the player.
Definition: suffer.cpp:1946

References addict_effect(), addictions, has_trait(), MIN_ADDICTION_LEVEL, rem_addiction(), trait_ADDICTIVE, and trait_NONADDICTIVE.

Referenced by suffer().

◆ suffer_from_artifacts()

void Character::suffer_from_artifacts ( )
private

Definition at line 1312 of file suffer.cpp.

1313{
1314 // Artifact effects
1316 add_effect( effect_attention, 3_turns );
1317 }
1318
1320 get_weather().weather_id->precip < precip_class::heavy ) {
1324 }
1325
1326 if( has_artifact_with( AEP_MUTAGENIC ) && one_turn_in( 48_hours ) ) {
1327 mutate();
1328 }
1329 if( has_artifact_with( AEP_FORCE_TELEPORT ) && one_turn_in( 1_hours ) ) {
1330 teleport::teleport( *this );
1331 }
1332}
const weather_type_id & get_bad_weather() const
weather_type_id weather_override
Definition: weather.h:199
@ AEP_MUTAGENIC
Definition: enums.h:130
@ AEP_FORCE_TELEPORT
Definition: enums.h:138
@ AEP_ATTENTION
Definition: enums.h:131
@ AEP_BAD_WEATHER
Definition: enums.h:140
const weather_generator & get_cur_weather_gen() const
Definition: weather.cpp:1049
void set_nextweather(time_point t)
Definition: weather.cpp:1101
bool one_turn_in(const time_duration &duration)
Definition: rng.cpp:70
static const efftype_id effect_attention("attention")

References Creature::add_effect(), AEP_ATTENTION, AEP_BAD_WEATHER, AEP_FORCE_TELEPORT, AEP_MUTAGENIC, effect_attention, weather_generator::get_bad_weather(), weather_manager::get_cur_weather_gen(), get_weather(), has_artifact_with(), heavy, mutate(), calendar::once_every(), one_turn_in(), weather_manager::set_nextweather(), teleport::teleport(), calendar::turn, and weather_manager::weather_override.

Referenced by suffer().

◆ suffer_from_asthma()

void Character::suffer_from_asthma ( int  current_stim)
private

Definition at line 613 of file suffer.cpp.

614{
618 return;
619 }
620 if( !one_in( ( to_turns<int>( 6_hours ) - current_stim * 300 ) *
621 ( has_effect( effect_sleep ) ? 10 : 1 ) ) ) {
622 return;
623 }
624 bool auto_use = has_charges( itype_inhaler, 1 ) || has_charges( itype_oxygen_tank, 1 ) ||
626 bool oxygenator = has_bionic( bio_gills ) && get_power_level() >= 3_kJ;
627 if( underwater ) {
628 oxygen = oxygen / 2;
629 auto_use = false;
630 }
631
632 add_msg_player_or_npc( m_bad, _( "You have an asthma attack!" ),
633 "<npcname> starts wheezing and coughing." );
634
636 inventory map_inv;
637 map_inv.form_from_map( g->u.pos(), 2, &g->u );
638 // check if an inhaler is somewhere near
639 bool nearby_use = auto_use || oxygenator || map_inv.has_charges( itype_inhaler, 1 ) ||
640 map_inv.has_charges( itype_oxygen_tank, 1 ) ||
641 map_inv.has_charges( itype_smoxygen_tank, 1 );
642 // check if character has an oxygenator first
643 if( oxygenator ) {
644 mod_power_level( -3_kJ );
645 add_msg_if_player( m_info, _( "You use your Oxygenator to clear it up, "
646 "then go back to sleep." ) );
647 } else if( auto_use ) {
649 add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
650 } else if( use_charges_if_avail( itype_oxygen_tank, 1 ) ||
652 add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
653 "and go back to sleep." ) );
654 }
655 } else if( nearby_use ) {
656 // create new variable to resolve a reference issue
657 int amount = 1;
658 if( !g->m.use_charges( g->u.pos(), 2, itype_inhaler, amount ).empty() ) {
659 add_msg_if_player( m_info, _( "You use your inhaler and go back to sleep." ) );
660 } else if( !g->m.use_charges( g->u.pos(), 2, itype_oxygen_tank, amount ).empty() ||
661 !g->m.use_charges( g->u.pos(), 2, itype_smoxygen_tank, amount ).empty() ) {
662 add_msg_if_player( m_info, _( "You take a deep breath from your oxygen tank "
663 "and go back to sleep." ) );
664 }
665 } else {
666 add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
667 if( has_effect( effect_sleep ) ) {
668 wake_up();
669 } else {
670 if( !is_npc() ) {
671 g->cancel_activity_or_ignore_query( distraction_type::asthma,
672 _( "You can't focus while choking!" ) );
673 }
674 }
675 }
676 } else if( auto_use ) {
677 int charges = 0;
679 moves -= 40;
680 charges = charges_of( itype_inhaler );
681 if( charges == 0 ) {
682 add_msg_if_player( m_bad, _( "You use your last inhaler charge." ) );
683 } else {
684 add_msg_if_player( m_info, vgettext( "You use your inhaler, "
685 "only %d charge left.",
686 "You use your inhaler, "
687 "only %d charges left.", charges ),
688 charges );
689 }
690 } else if( use_charges_if_avail( itype_oxygen_tank, 1 ) ||
692 moves -= 500; // synched with use action
694 if( charges == 0 ) {
695 add_msg_if_player( m_bad, _( "You breathe in last bit of oxygen "
696 "from the tank." ) );
697 } else {
698 add_msg_if_player( m_info, vgettext( "You take a deep breath from your oxygen "
699 "tank, only %d charge left.",
700 "You take a deep breath from your oxygen "
701 "tank, only %d charges left.", charges ),
702 charges );
703 }
704 }
705 } else {
706 add_effect( effect_asthma, rng( 5_minutes, 20_minutes ) );
707 if( !is_npc() ) {
708 g->cancel_activity_or_ignore_query( distraction_type::asthma,
709 _( "You can't focus while choking!" ) );
710 }
711 }
712}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9663
bool has_charges(const itype_id &it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >) const
Definition: inventory.cpp:890
static const efftype_id effect_datura("datura")
static const efftype_id effect_narcosis("narcosis")
static const efftype_id effect_adrenaline("adrenaline")
static const efftype_id effect_asthma("asthma")
static const itype_id itype_oxygen_tank("oxygen_tank")
static const itype_id itype_inhaler("inhaler")
static const itype_id itype_smoxygen_tank("smoxygen_tank")
static const bionic_id bio_gills("bio_gills")
static const efftype_id effect_took_antiasthmatic("took_antiasthmatic")

References _, Creature::add_effect(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), asthma, bio_gills, visitable< Character >::charges_of(), effect_adrenaline, effect_asthma, effect_datura, effect_narcosis, effect_sleep, effect_took_antiasthmatic, inventory::form_from_map(), g, get_power_level(), has_bionic(), has_charges(), inventory::has_charges(), Creature::has_effect(), in_sleep_state(), Creature::is_npc(), itype_inhaler, itype_oxygen_tank, itype_smoxygen_tank, m_bad, m_info, mod_power_level(), Creature::moves, one_in(), oxygen, rng(), Creature::underwater, use_charges_if_avail(), vgettext(), and wake_up().

Referenced by suffer().

◆ suffer_from_bad_bionics()

void Character::suffer_from_bad_bionics ( )
private

Definition at line 1222 of file suffer.cpp.

1223{
1224 // Negative bionics effects
1225 if( has_bionic( bio_dis_shock ) && get_power_level() > 9_kJ && one_turn_in( 2_hours ) &&
1227 add_msg_if_player( m_bad, _( "You suffer a painful electrical discharge!" ) );
1228 mod_pain( 1 );
1229 moves -= 150;
1230 mod_power_level( -10_kJ );
1231
1232 if( weapon.typeId() == itype_e_handcuffs && weapon.charges > 0 ) {
1233 weapon.charges -= rng( 1, 3 ) * 50;
1234 if( weapon.charges < 1 ) {
1235 weapon.charges = 1;
1236 }
1237
1238 add_msg_if_player( m_good, _( "The %s seems to be affected by the discharge." ),
1239 weapon.tname() );
1240 }
1241 sfx::play_variant_sound( "bionics", "elec_discharge", 100 );
1242 }
1243 if( has_bionic( bio_dis_acid ) && one_turn_in( 150_minutes ) ) {
1244 add_msg_if_player( m_bad, _( "You suffer a burning acidic discharge!" ) );
1245 hurtall( 1, nullptr );
1246 sfx::play_variant_sound( "bionics", "acid_discharge", 100 );
1247 sfx::do_player_death_hurt( g->u, false );
1248 }
1249 if( has_bionic( bio_drain ) && get_power_level() > 24_kJ && one_turn_in( 1_hours ) ) {
1250 add_msg_if_player( m_bad, _( "Your batteries discharge slightly." ) );
1251 mod_power_level( -25_kJ );
1252 sfx::play_variant_sound( "bionics", "elec_crackle_low", 100 );
1253 }
1254 if( has_bionic( bio_noise ) && one_turn_in( 50_minutes ) &&
1256 // TODO: NPCs with said bionic
1257 if( !is_deaf() ) {
1258 add_msg( m_bad, _( "A bionic emits a crackle of noise!" ) );
1259 sfx::play_variant_sound( "bionics", "elec_blast", 100 );
1260 } else {
1261 add_msg( m_bad, _( "You feel your faulty bionic shuddering." ) );
1262 sfx::play_variant_sound( "bionics", "elec_blast_muffled", 100 );
1263 }
1264 sounds::sound( pos(), 60, sounds::sound_t::movement, _( "Crackle!" ) ); //sfx above
1265 }
1267 get_power_level() >= get_max_power_level() * .75 ) {
1268 mod_str_bonus( -3 );
1269 }
1270 if( has_bionic( bio_trip ) && one_turn_in( 50_minutes ) &&
1273 add_msg_if_player( m_bad, _( "Your vision pixelates!" ) );
1274 add_effect( effect_visuals, 10_minutes );
1275 sfx::play_variant_sound( "bionics", "pixelated", 100 );
1276 }
1277 if( has_bionic( bio_spasm ) && one_turn_in( 5_hours ) && !has_effect( effect_downed ) &&
1280 _( "Your malfunctioning bionic causes you to spasm and fall to the floor!" ) );
1281 mod_pain( 1 );
1282 add_effect( effect_stunned, 1_turns );
1283 add_effect( effect_downed, 10_turns, num_bp, 0 );
1284 sfx::play_variant_sound( "bionics", "elec_crackle_high", 100 );
1285 }
1286 if( has_bionic( bio_shakes ) && get_power_level() > 24_kJ && one_turn_in( 2_hours ) ) {
1287 add_msg_if_player( m_bad, _( "Your bionics short-circuit, causing you to tremble and shiver." ) );
1288 mod_power_level( -25_kJ );
1289 add_effect( effect_shakes, 5_minutes );
1290 sfx::play_variant_sound( "bionics", "elec_crackle_med", 100 );
1291 }
1292 if( has_bionic( bio_leaky ) && one_turn_in( 6_minutes ) ) {
1293 mod_healthy_mod( -1, -200 );
1294 }
1295 if( has_bionic( bio_sleepy ) && one_turn_in( 50_minutes ) && !in_sleep_state() ) {
1296 mod_fatigue( 1 );
1297 }
1298 if( has_bionic( bio_itchy ) && one_turn_in( 50_minutes ) && !has_effect( effect_formication ) &&
1300 add_msg_if_player( m_bad, _( "Your malfunctioning bionic itches!" ) );
1301 body_part bp = random_body_part( true );
1302 add_effect( effect_formication, 10_minutes, bp );
1303 }
1304 if( has_bionic( bio_glowy ) && !has_effect( effect_glowy_led ) && one_turn_in( 50_minutes ) &&
1305 get_power_level() > 1_kJ ) {
1306 add_msg_if_player( m_bad, _( "Your malfunctioning bionic starts to glow!" ) );
1307 add_effect( effect_glowy_led, 5_minutes );
1308 mod_power_level( -1_kJ );
1309 }
1310}
body_part random_body_part(bool main_parts_only)
Returns a random body_part token.
Definition: bodypart.cpp:364
void do_player_death_hurt(const player &target, bool death)
Definition: sounds.cpp:1633
static const bionic_id bio_shakes("bio_shakes")
static const efftype_id effect_glowy_led("glowy_led")
static const efftype_id effect_downed("downed")
static const bionic_id bio_power_weakness("bio_power_weakness")
static const bionic_id bio_dis_shock("bio_dis_shock")
static const bionic_id bio_glowy("bio_glowy")
static const efftype_id effect_visuals("visuals")
static const bionic_id bio_trip("bio_trip")
static const bionic_id bio_dis_acid("bio_dis_acid")
static const itype_id itype_e_handcuffs("e_handcuffs")
static const bionic_id bio_spasm("bio_spasm")
static const bionic_id bio_sleepy("bio_sleepy")
static const bionic_id bio_noise("bio_noise")
static const efftype_id effect_shakes("shakes")
static const efftype_id effect_stunned("stunned")
static const efftype_id effect_formication("formication")
static const bionic_id bio_drain("bio_drain")
static const bionic_id bio_itchy("bio_itchy")
static const bionic_id bio_leaky("bio_leaky")

References _, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), bio_dis_acid, bio_dis_shock, bio_drain, bio_glowy, bio_itchy, bio_leaky, bio_noise, bio_power_weakness, bio_shakes, bio_sleepy, bio_spasm, bio_trip, item::charges, sfx::do_player_death_hurt(), effect_downed, effect_formication, effect_glowy_led, effect_narcosis, effect_shakes, effect_stunned, effect_visuals, g, get_max_power_level(), get_power_level(), has_bionic(), Creature::has_effect(), has_max_power(), hurtall(), in_sleep_state(), is_deaf(), itype_e_handcuffs, m_bad, m_good, mod_fatigue(), mod_healthy_mod(), Creature::mod_pain(), mod_power_level(), mod_str_bonus(), sounds::movement, Creature::moves, num_bp, one_turn_in(), sfx::play_variant_sound(), pos(), random_body_part(), rng(), sounds::sound(), item::tname(), item::typeId(), and weapon.

Referenced by suffer().

◆ suffer_from_chemimbalance()

void Character::suffer_from_chemimbalance ( )
private

Definition at line 366 of file suffer.cpp.

367{
368 if( one_turn_in( 6_hours ) && !has_trait( trait_NOPAIN ) ) {
369 add_msg_if_player( m_bad, _( "You suddenly feel sharp pain for no reason." ) );
370 mod_pain( 3 * rng( 1, 3 ) );
371 }
372 if( one_turn_in( 6_hours ) ) {
373 int pkilladd = 5 * rng( -1, 2 );
374 if( pkilladd > 0 ) {
375 add_msg_if_player( m_bad, _( "You suddenly feel numb." ) );
376 } else if( ( pkilladd < 0 ) && ( !( has_trait( trait_NOPAIN ) ) ) ) {
377 add_msg_if_player( m_bad, _( "You suddenly ache." ) );
378 }
379 mod_painkiller( pkilladd );
380 }
381 if( one_turn_in( 6_hours ) && !has_effect( effect_sleep ) ) {
382 add_msg_if_player( m_bad, _( "You feel dizzy for a moment." ) );
383 moves -= rng( 10, 30 );
384 }
385 if( one_turn_in( 6_hours ) ) {
386 int hungadd = 5 * rng( -1, 3 );
387 if( hungadd > 0 ) {
388 add_msg_if_player( m_bad, _( "You suddenly feel hungry." ) );
389 } else {
390 add_msg_if_player( m_good, _( "You suddenly feel a little full." ) );
391 }
392 mod_stored_kcal( -10 * hungadd );
393 }
394 if( one_turn_in( 6_hours ) ) {
395 add_msg_if_player( m_bad, _( "You suddenly feel thirsty." ) );
396 mod_thirst( 5 * rng( 1, 3 ) );
397 }
398 if( one_turn_in( 6_hours ) ) {
399 add_msg_if_player( m_good, _( "You feel fatigued all of a sudden." ) );
400 mod_fatigue( 10 * rng( 2, 4 ) );
401 }
402 if( one_turn_in( 8_hours ) ) {
403 if( one_in( 3 ) ) {
405 } else {
406 add_morale( MORALE_FEELING_BAD, -20, -100 );
407 }
408 }
409 if( one_turn_in( 6_hours ) ) {
410 if( one_in( 3 ) ) {
411 add_msg_if_player( m_bad, _( "You suddenly feel very cold." ) );
413 } else {
414 add_msg_if_player( m_bad, _( "You suddenly feel cold." ) );
415 temp_cur.fill( BODYTEMP_COLD );
416 }
417 }
418 if( one_turn_in( 6_hours ) ) {
419 if( one_in( 3 ) ) {
420 add_msg_if_player( m_bad, _( "You suddenly feel very hot." ) );
422 } else {
423 add_msg_if_player( m_bad, _( "You suddenly feel hot." ) );
424 temp_cur.fill( BODYTEMP_HOT );
425 }
426 }
427}
const morale_type MORALE_FEELING_BAD("morale_feeling_bad")
static const trait_id trait_NOPAIN("NOPAIN")

References _, add_morale(), Creature::add_msg_if_player(), BODYTEMP_COLD, BODYTEMP_HOT, BODYTEMP_VERY_COLD, BODYTEMP_VERY_HOT, effect_sleep, Creature::has_effect(), has_trait(), m_bad, m_good, mod_fatigue(), Creature::mod_pain(), mod_painkiller(), mod_stored_kcal(), mod_thirst(), MORALE_FEELING_BAD, MORALE_FEELING_GOOD, Creature::moves, one_in(), one_turn_in(), rng(), temp_cur, and trait_NOPAIN.

Referenced by suffer_while_awake().

◆ suffer_from_other_mutations()

void Character::suffer_from_other_mutations ( )
private

Definition at line 941 of file suffer.cpp.

942{
943 if( has_trait( trait_SHARKTEETH ) && one_turn_in( 24_hours ) ) {
944 add_msg_if_player( m_neutral, _( "You shed a tooth!" ) );
945 g->m.spawn_item( pos(), "bone", 1 );
946 }
947
949 //~Sound of buzzing Insect Wings
950 sounds::sound( pos(), 10, sounds::sound_t::movement, _( "BZZZZZ" ), false, "misc",
951 "insect_wings" );
952 }
953
954 bool wearing_shoes = is_wearing_shoes( side::LEFT ) || is_wearing_shoes( side::RIGHT );
955 int root_vitamins = 0;
956 int root_water = 0;
957 if( has_trait( trait_ROOTS3 ) && g->m.has_flag( flag_PLOWABLE, pos() ) && !wearing_shoes ) {
958 root_vitamins += 1;
960 root_water += 51;
961 }
962 }
963
964 if( x_in_y( root_vitamins, 576 ) ) {
965 vitamin_mod( vitamin_id( "iron" ), 1, true );
966 vitamin_mod( vitamin_id( "calcium" ), 1, true );
967 mod_healthy_mod( 5, 50 );
968 }
969
970 if( x_in_y( root_water, 2550 ) ) {
971 // Plants draw some crazy amounts of water from the ground in real life,
972 // so these numbers try to reflect that uncertain but large amount
973 // this should take 12 hours to meet your daily needs with ROOTS2, and 8 with ROOTS3
974 mod_thirst( -1 );
975 }
976
977 if( has_trait( trait_SORES ) ) {
978 for( const body_part bp : all_body_parts ) {
979 if( bp == bp_head ) {
980 continue;
981 }
982 int sores_pain = 5 + 0.4 * std::abs( encumb( bp ) );
983 if( get_pain() < sores_pain ) {
984 set_pain( sores_pain );
985 }
986 }
987 }
988 //Web Weavers...weave web
990 // this adds intensity to if its not already there.
991 g->m.add_field( pos(), fd_web, 1 );
992
993 }
994
995 // Blind/Deaf for brief periods about once an hour,
996 // and visuals about once every 30 min.
997 if( has_trait( trait_PER_SLIME ) ) {
998 if( one_turn_in( 1_hours ) && !has_effect( effect_deaf ) ) {
999 add_msg_if_player( m_bad, _( "Suddenly, you can't hear anything!" ) );
1000 add_effect( effect_deaf, rng( 20_minutes, 60_minutes ) );
1001 }
1002 if( one_turn_in( 1_hours ) && !( has_effect( effect_blind ) ) ) {
1003 add_msg_if_player( m_bad, _( "Suddenly, your eyes stop working!" ) );
1004 add_effect( effect_blind, rng( 2_minutes, 6_minutes ) );
1005 }
1006 // Yes, you can be blind and hallucinate at the same time.
1007 // Your post-human biology is truly remarkable.
1008 if( one_turn_in( 30_minutes ) && !( has_effect( effect_visuals ) ) ) {
1009 add_msg_if_player( m_bad, _( "Your visual centers must be acting up…" ) );
1010 add_effect( effect_visuals, rng( 36_minutes, 72_minutes ) );
1011 }
1012 }
1013
1014 if( has_trait( trait_WEB_SPINNER ) && !in_vehicle && one_in( 3 ) ) {
1015 // this adds intensity to if its not already there.
1016 g->m.add_field( pos(), fd_web, 1 );
1017 }
1018
1019 bool should_mutate = has_trait( trait_UNSTABLE ) && !has_trait( trait_CHAOTIC_BAD ) &&
1020 one_turn_in( 48_hours );
1021 should_mutate |= ( has_trait( trait_CHAOTIC ) || has_trait( trait_CHAOTIC_BAD ) ) &&
1022 one_turn_in( 12_hours );
1023 if( should_mutate ) {
1024 mutate();
1025 }
1026
1027 const bool needs_fire = !has_morale( MORALE_PYROMANIA_NEARFIRE ) &&
1029 if( has_trait( trait_PYROMANIA ) && needs_fire && !in_sleep_state() &&
1030 calendar::once_every( 2_hours ) ) {
1031 add_morale( MORALE_PYROMANIA_NOFIRE, -1, -30, 24_hours, 24_hours, true );
1032 if( calendar::once_every( 4_hours ) ) {
1033 const translation smokin_hot_fiyah =
1034 SNIPPET.random_from_category( "pyromania_withdrawal" ).value_or( translation() );
1035 add_msg_if_player( m_bad, "%s", smokin_hot_fiyah );
1036 }
1037 }
1039 calendar::once_every( 2_hours ) ) {
1041 const translation snip = SNIPPET.random_from_category( "killer_withdrawal" ).value_or(
1042 translation() );
1043 add_msg_if_player( m_bad, "%s", snip );
1044 }
1045 add_morale( MORALE_KILLER_NEED_TO_KILL, -1, -30, 24_hours, 24_hours );
1046 }
1047}
bool has_morale(const morale_type &type) const
Definition: character.cpp:9116
virtual void set_pain(int npain)
Definition: creature.cpp:1357
const morale_type MORALE_KILLER_HAS_KILLED("morale_killer_has_killed")
const morale_type MORALE_PYROMANIA_STARTFIRE("morale_pyromania_startfire")
const morale_type MORALE_KILLER_NEED_TO_KILL("morale_killer_need_to_kill")
const morale_type MORALE_PYROMANIA_NEARFIRE("morale_pyromania_nearfire")
const morale_type MORALE_PYROMANIA_NOFIRE("morale_pyromania_nofire")
static const efftype_id effect_blind("blind")
static const trait_id trait_PER_SLIME("PER_SLIME")
static const trait_id trait_SHARKTEETH("SHARKTEETH")
static const trait_id trait_CHAOTIC("CHAOTIC")
static const trait_id trait_UNSTABLE("UNSTABLE")
static const trait_id trait_PYROMANIA("PYROMANIA")
static const efftype_id effect_deaf("deaf")
static const trait_id trait_WEB_WEAVER("WEB_WEAVER")
static const trait_id trait_CHAOTIC_BAD("CHAOTIC_BAD")
static const trait_id trait_WINGS_INSECT("WINGS_INSECT")
static const trait_id trait_SORES("SORES")
static const trait_id trait_KILLER("KILLER")
static const trait_id trait_WEB_SPINNER("WEB_SPINNER")
static const std::string flag_PLOWABLE("PLOWABLE")
static const trait_id trait_ROOTS3("ROOTS3")

References _, Creature::add_effect(), add_morale(), Creature::add_msg_if_player(), all_body_parts, bp_head, effect_blind, effect_deaf, effect_visuals, encumb(), fd_web, flag_PLOWABLE(), g, Creature::get_pain(), get_thirst(), has_active_mutation(), Creature::has_effect(), has_morale(), has_trait(), in_sleep_state(), in_vehicle, is_wearing_shoes(), LEFT, m_bad, m_neutral, mod_healthy_mod(), mod_thirst(), MORALE_KILLER_HAS_KILLED, MORALE_KILLER_NEED_TO_KILL, MORALE_PYROMANIA_NEARFIRE, MORALE_PYROMANIA_NOFIRE, MORALE_PYROMANIA_STARTFIRE, sounds::movement, mutate(), calendar::once_every(), one_in(), one_turn_in(), pos(), snippet_library::random_from_category(), RIGHT, rng(), Creature::set_pain(), SNIPPET, sounds::sound(), trait_CHAOTIC, trait_CHAOTIC_BAD, trait_KILLER, trait_PER_SLIME, trait_PYROMANIA, trait_ROOTS3, trait_SHARKTEETH, trait_SORES, trait_UNSTABLE, trait_WEB_SPINNER, trait_WEB_WEAVER, trait_WINGS_INSECT, turgid, vitamin_mod(), and x_in_y().

Referenced by suffer().

◆ suffer_from_pain()

void Character::suffer_from_pain ( )
private

Definition at line 1463 of file suffer.cpp.

1464{
1465}

Referenced by suffer().

◆ suffer_from_radiation()

void Character::suffer_from_radiation ( )
private

Definition at line 1049 of file suffer.cpp.

1050{
1051 // checking for radioactive items in inventory
1052 const int item_radiation = leak_level( "RADIOACTIVE" );
1053 const int map_radiation = g->m.get_radiation( pos() );
1054 float rads = map_radiation / 100.0f + item_radiation / 10.0f;
1055
1056 int rad_mut = 0;
1057 if( has_trait( trait_RADIOACTIVE3 ) ) {
1058 rad_mut = 3;
1059 } else if( has_trait( trait_RADIOACTIVE2 ) ) {
1060 rad_mut = 2;
1061 } else if( has_trait( trait_RADIOACTIVE1 ) ) {
1062 rad_mut = 1;
1063 }
1064
1065 // Spread less radiation when sleeping (slower metabolism etc.)
1066 // Otherwise it can quickly get to the point where you simply can't sleep at all
1067 const bool rad_mut_proc = rad_mut > 0 && x_in_y( rad_mut, to_turns<int>( in_sleep_state() ?
1068 3_hours : 30_minutes ) );
1069
1070 bool has_helmet = false;
1071 const bool power_armored = is_wearing_power_armor( &has_helmet );
1072 const bool rad_resist = power_armored || worn_with_flag( flag_RAD_RESIST );
1073
1074 if( rad_mut > 0 ) {
1075 const bool kept_in = is_rad_immune() || ( rad_resist && !one_in( 4 ) );
1076 if( kept_in ) {
1077 // As if standing on a map tile with radiation level equal to rad_mut
1078 rads += rad_mut / 100.0f;
1079 }
1080
1081 if( rad_mut_proc && !kept_in ) {
1082 // Irradiate a random nearby point
1083 // If you can't, irradiate the player instead
1084 tripoint rad_point = pos() + point( rng( -3, 3 ), rng( -3, 3 ) );
1085 // TODO: Radioactive vehicles?
1086 if( g->m.get_radiation( rad_point ) < rad_mut ) {
1087 g->m.adjust_radiation( rad_point, 1 );
1088 } else {
1089 rads += rad_mut;
1090 }
1091 }
1092 }
1093
1094 // Used to control vomiting from radiation to make it not-annoying
1095 bool radiation_increasing = irradiate( rads );
1096
1097 if( radiation_increasing && calendar::once_every( 3_minutes ) && has_bionic( bio_geiger ) ) {
1099 _( "You feel an anomalous sensation coming from "
1100 "your radiation sensors." ) );
1101 }
1102
1103 if( calendar::once_every( 15_minutes ) ) {
1104 if( get_rad() < 0 ) {
1105 set_rad( 0 );
1106 } else if( get_rad() > 2000 ) {
1107 set_rad( 2000 );
1108 }
1109 if( get_option<bool>( "RAD_MUTATION" ) && rng( 100, 10000 ) < get_rad() ) {
1110 mutate();
1111 mod_rad( -50 );
1112 } else if( get_rad() > 50 && rng( 1, 3000 ) < get_rad() && ( stomach.get_calories() > 0 ||
1113 radiation_increasing || !in_sleep_state() ) ) {
1114 vomit();
1115 mod_rad( -1 );
1116 }
1117 }
1118
1119 const bool radiogenic = has_trait( trait_RADIOGENIC );
1120 if( radiogenic && calendar::once_every( 30_minutes ) && get_rad() > 0 ) {
1121 // At 200 irradiation, twice as fast as REGEN
1122 if( x_in_y( get_rad(), 200 ) ) {
1123 healall( 1 );
1124 if( rad_mut == 0 ) {
1125 // Don't heal radiation if we're generating it naturally
1126 // That would counter the main downside of radioactivity
1127 mod_rad( -5 );
1128 }
1129 }
1130 }
1131
1132 if( !radiogenic && get_rad() > 0 ) {
1133 // Even if you heal the radiation itself, the damage is done.
1134 const int hmod = get_healthy_mod();
1135 if( hmod > 200 - get_rad() ) {
1136 set_healthy_mod( std::max( -200, 200 - get_rad() ) );
1137 }
1138 }
1139
1140 if( get_rad() > 200 && calendar::once_every( 10_minutes ) && x_in_y( get_rad(), 1000 ) ) {
1141 hurtall( 1, nullptr );
1142 mod_rad( -5 );
1143 }
1144
1145 if( !reactor_plut && !tank_plut && !slow_rad ) {
1146 return;
1147 }
1148 // Microreactor CBM and supporting bionics
1150 //first do the filtering of plutonium from storage to reactor
1151 if( tank_plut > 0 ) {
1152 int plut_trans;
1154 plut_trans = tank_plut * 0.025;
1155 } else {
1156 plut_trans = tank_plut * 0.005;
1157 }
1158 if( plut_trans < 1 ) {
1159 plut_trans = 1;
1160 }
1161 tank_plut -= plut_trans;
1162 reactor_plut += plut_trans;
1163 }
1164 //leaking radiation, reactor is unshielded, but still better than a simple tank
1165 slow_rad += ( ( tank_plut * 0.1 ) + ( reactor_plut * 0.01 ) );
1166 //begin power generation
1167 if( reactor_plut > 0 ) {
1168 int power_gen = 0;
1169 if( has_bionic( bio_advreactor ) ) {
1170 if( ( reactor_plut * 0.05 ) > 2000 ) {
1171 power_gen = 2000;
1172 } else {
1173 power_gen = reactor_plut * 0.05;
1174 if( power_gen < 1 ) {
1175 power_gen = 1;
1176 }
1177 }
1178 slow_rad += ( power_gen * 3 );
1179 while( slow_rad >= 50 ) {
1180 if( power_gen >= 1 ) {
1181 slow_rad -= 50;
1182 power_gen -= 1;
1183 reactor_plut -= 1;
1184 } else {
1185 break;
1186 }
1187 }
1188 } else if( has_bionic( bio_reactor ) ) {
1189 if( ( reactor_plut * 0.025 ) > 500 ) {
1190 power_gen = 500;
1191 } else {
1192 power_gen = reactor_plut * 0.025;
1193 if( power_gen < 1 ) {
1194 power_gen = 1;
1195 }
1196 }
1197 slow_rad += ( power_gen * 3 );
1198 }
1199 reactor_plut -= power_gen;
1200 while( power_gen >= 250 ) {
1201 apply_damage( nullptr, bodypart_id( "torso" ), 1 );
1202 mod_pain( 1 );
1204 _( "Your chest burns as your power systems overload!" ) );
1205 mod_power_level( 50_kJ );
1206 power_gen -= 60; // ten units of power lost due to short-circuiting into you
1207 }
1208 mod_power_level( units::from_kilojoule( power_gen ) );
1209 }
1210 } else {
1211 slow_rad += ( reactor_plut + tank_plut ) * 40;
1212 //plutonium in body without any kind of container. Not good at all.
1213 reactor_plut *= 0.6;
1214 tank_plut *= 0.6;
1215 }
1216 while( slow_rad >= 1000 ) {
1217 mod_rad( 1 );
1218 slow_rad -= 1000;
1219 }
1220}
virtual int get_healthy_mod() const
Definition: character.cpp:4161
virtual void set_healthy_mod(int nhealthy_mod)
Definition: character.cpp:4270
static const bionic_id bio_geiger("bio_geiger")
static const std::string flag_RAD_RESIST("RAD_RESIST")
static const bionic_id bio_reactor("bio_reactor")
static const bionic_id bio_plut_filter("bio_plut_filter")
static const bionic_id bio_advreactor("bio_advreactor")

References _, Creature::add_msg_if_player(), apply_damage(), bio_advreactor, bio_geiger, bio_plut_filter, bio_reactor, flag_RAD_RESIST(), units::from_kilojoule(), g, stomach_contents::get_calories(), get_healthy_mod(), get_rad(), has_active_bionic(), has_bionic(), has_trait(), healall(), hurtall(), in_sleep_state(), irradiate(), is_rad_immune(), is_wearing_power_armor(), leak_level(), m_bad, m_warning, Creature::mod_pain(), mod_power_level(), mod_rad(), mutate(), calendar::once_every(), one_in(), pos(), reactor_plut, rng(), set_healthy_mod(), set_rad(), slow_rad, stomach, tank_plut, trait_RADIOACTIVE1, trait_RADIOACTIVE2, trait_RADIOACTIVE3, trait_RADIOGENIC, vomit(), worn_with_flag(), and x_in_y().

Referenced by suffer().

◆ suffer_from_schizophrenia()

void Character::suffer_from_schizophrenia ( )
private

Definition at line 429 of file suffer.cpp.

430{
431 std::string i_name_w;
432 if( !weapon.is_null() ) {
433 i_name_w = weapon.has_var( "item_label" ) ? weapon.get_var( "item_label" ) :
434 //~ %1$s: weapon name
435 string_format( _( "your %1$s" ), weapon.type_name() );
436 }
437 // Start with the effects that both NPCs and avatars can suffer from
438 // Delusions
439 if( one_turn_in( 8_hours ) ) {
440 if( rng( 1, 20 ) > 5 ) { // 75% chance
441 const translation snip = SNIPPET.random_from_category( "schizo_delusion_paranoid" ).value_or(
442 translation() );
443 add_msg_if_player( m_warning, "%s", snip );
444 add_morale( MORALE_FEELING_BAD, -20, -100 );
445 } else { // 25% chance
446 const translation snip = SNIPPET.random_from_category( "schizo_delusion_grandiose" ).value_or(
447 translation() );
448 add_msg_if_player( m_good, "%s", snip );
450 }
451 return;
452 }
453 // Formication
454 if( one_turn_in( 6_hours ) ) {
455 const translation snip = SNIPPET.random_from_category( "schizo_formication" ).value_or(
456 translation() );
457 body_part bp = random_body_part( true );
458 add_effect( effect_formication, 45_minutes, bp );
459 add_msg_if_player( m_bad, "%s", snip );
460 return;
461 }
462 // Numbness
463 if( one_turn_in( 4_hours ) ) {
464 add_msg_if_player( m_bad, _( "You suddenly feel so numb…" ) );
465 mod_painkiller( 25 );
466 return;
467 }
468 // Hallucination
469 if( one_turn_in( 6_hours ) ) {
470 add_effect( effect_hallu, 6_hours );
471 return;
472 }
473 // Visuals
474 if( one_turn_in( 2_hours ) ) {
475 add_effect( effect_visuals, rng( 15_turns, 60_turns ) );
476 return;
477 }
478 // Shaking
479 if( !has_effect( effect_valium ) && one_turn_in( 4_hours ) ) {
480 add_msg_player_or_npc( m_bad, _( "You start to shake uncontrollably." ),
481 _( "<npcname> starts to shake uncontrollably." ) );
482 add_effect( effect_shakes, rng( 2_minutes, 5_minutes ) );
483 return;
484 }
485 // Shout
486 if( one_turn_in( 4_hours ) ) {
487 shout( SNIPPET.random_from_category( "schizo_self_shout" ).value_or( translation() ).translated() );
488 return;
489 }
490 // Drop weapon
491 if( one_turn_in( 2_days ) && !weapon.is_null() ) {
492 const translation snip = SNIPPET.random_from_category( "schizo_weapon_drop" ).value_or(
493 translation() );
494 std::string str = string_format( snip, i_name_w );
495 str[0] = toupper( str[0] );
496
497 add_msg_if_player( m_bad, "%s", str );
498 item_location loc( *this, &weapon );
499 drop( loc, pos() );
500 return;
501 }
502 // Talk to self
503 if( one_turn_in( 4_hours ) ) {
504 const translation snip = SNIPPET.random_from_category( "schizo_self_talk" ).value_or(
505 translation() );
506 add_msg( _( "%1$s says: \"%2$s\"" ), name, snip );
507 return;
508 }
509
510 // effects of this point are entirely internal, so NPCs can't suffer from them
511 if( is_npc() ) {
512 return;
513 }
514 // Sound
515 if( one_turn_in( 4_hours ) ) {
516 sound_hallu();
517 }
518 // Follower turns hostile
519 if( one_turn_in( 4_hours ) ) {
520 std::vector<shared_ptr_fast<npc>> followers = overmap_buffer.get_npcs_near_player( 12 );
521
522 std::string who_gets_angry = name;
523 if( !followers.empty() ) {
524 who_gets_angry = random_entry_ref( followers )->name;
525 }
526 add_msg( m_bad, _( "%1$s gets angry!" ), who_gets_angry );
527 return;
528 }
529
530 // Monster dies
531 if( one_turn_in( 6_hours ) ) {
532 // TODO: move to monster group json
533 static const std::array<mtype_id, 5> monsters = { {
535 }
536 };
537 add_msg( _( "%s dies!" ), random_entry_ref( monsters )->nname() );
538 return;
539 }
540
541 // Limb Breaks
542 if( one_turn_in( 4_hours ) ) {
543 const translation snip = SNIPPET.random_from_category( "broken_limb" ).value_or( translation() );
544 add_msg( m_bad, "%s", snip );
545 return;
546 }
547
548 // NPC chat
549 if( one_turn_in( 4_hours ) ) {
550 std::string i_name = Name::generate( one_in( 2 ) );
551
552 std::string i_talk = SNIPPET.expand( SNIPPET.random_from_category( "<lets_talk>" ).value_or(
553 translation() ).translated() );
554 parse_tags( i_talk, *this, *this );
555
556 add_msg( _( "%1$s says: \"%2$s\"" ), i_name, i_talk );
557 return;
558 }
559
560 // Skill raise
561 if( one_turn_in( 12_hours ) ) {
562 skill_id raised_skill = Skill::random_skill();
563 add_msg( m_good, _( "You increase %1$s to level %2$d." ), raised_skill.obj().name(),
564 get_skill_level( raised_skill ) + 1 );
565 return;
566 }
567
568 // Talking weapon
569 if( !weapon.is_null() ) {
570 // If player has a weapon, picks a message from said weapon
571 // Weapon tells player to kill a monster if any are nearby
572 // Weapon is concerned for player if bleeding
573 // Weapon is concerned for itself if damaged
574 // Otherwise random chit-chat
575 std::vector<weak_ptr_fast<monster>> mons = g->all_monsters().items;
576
577 std::string i_talk_w;
578 bool does_talk = false;
579 if( !mons.empty() && one_turn_in( 12_minutes ) ) {
580 std::vector<std::string> seen_mons;
581 for( weak_ptr_fast<monster> &n : mons ) {
582 if( sees( *n.lock() ) ) {
583 seen_mons.emplace_back( n.lock()->get_name() );
584 }
585 }
586 if( !seen_mons.empty() ) {
587 const translation talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_monster" ).value_or(
588 translation() );
589 i_talk_w = string_format( talk_w, random_entry_ref( seen_mons ) );
590 does_talk = true;
591 }
592 }
593 if( !does_talk && has_effect( effect_bleed ) && one_turn_in( 5_minutes ) ) {
594 i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_bleeding" ).value_or(
595 translation() ).translated();
596 does_talk = true;
597 } else if( weapon.damage() >= weapon.max_damage() / 3 && one_turn_in( 1_hours ) ) {
598 i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_damaged" ).value_or(
599 translation() ).translated();
600 does_talk = true;
601 } else if( one_turn_in( 4_hours ) ) {
602 i_talk_w = SNIPPET.random_from_category( "schizo_weapon_talk_misc" ).value_or(
603 translation() ).translated();
604 does_talk = true;
605 }
606 if( does_talk ) {
607 add_msg( _( "%1$s says: \"%2$s\"" ), i_name_w, i_talk_w );
608 return;
609 }
610 }
611}
void sound_hallu()
Creates an auditory hallucination.
Definition: suffer.cpp:1706
static skill_id random_skill()
Definition: skill.cpp:192
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1024
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6060
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1069
int damage() const
How much damage has the item sustained?
Definition: item.cpp:695
std::vector< shared_ptr_fast< npc > > get_npcs_near_player(int radius)
Same as get_npcs_near(int,int,int,int) but uses player position as center.
std::string expand(const std::string &str) const
Expand the string by recursively replacing tags in angle brackets (<>) with random snippets from the ...
std::weak_ptr< T > weak_ptr_fast
Definition: memory_fast.h:17
void parse_tags(std::string &phrase, const Character &u, const Character &me, const itype_id &item_type=itype_id::NULL_ID())
Definition: npctalk.cpp:1574
static const efftype_id effect_bleed("bleed")
static const mtype_id mon_zombie_cop("mon_zombie_cop")
static const efftype_id effect_hallu("hallu")
static const mtype_id mon_zombie_fireman("mon_zombie_fireman")
static const mtype_id mon_zombie_fat("mon_zombie_fat")
static const mtype_id mon_zombie_soldier("mon_zombie_soldier")
static const mtype_id mon_zombie("mon_zombie")
static const efftype_id effect_valium("valium")

References _, Creature::add_effect(), add_morale(), add_msg(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), item::damage(), drop(), effect_bleed, effect_formication, effect_hallu, effect_shakes, effect_valium, effect_visuals, snippet_library::expand(), g, Name::generate(), overmapbuffer::get_npcs_near_player(), get_skill_level(), item::get_var(), Creature::has_effect(), item::has_var(), Creature::is_npc(), item::is_null(), m_bad, m_good, m_warning, item::max_damage(), mod_painkiller(), mon_zombie, mon_zombie_cop, mon_zombie_fat, mon_zombie_fireman, mon_zombie_soldier, MORALE_FEELING_BAD, MORALE_FEELING_GOOD, name, Skill::name(), string_id< T >::obj(), one_in(), one_turn_in(), overmap_buffer, parse_tags(), pos(), random_body_part(), random_entry_ref(), snippet_library::random_from_category(), Skill::random_skill(), rng(), sees(), shout(), SNIPPET, sound_hallu(), string_format(), item::type_name(), and weapon.

Referenced by suffer_while_awake().

◆ suffer_from_stimulants()

void Character::suffer_from_stimulants ( int  current_stim)
private

Definition at line 1334 of file suffer.cpp.

1335{
1336 // Stim +250 kills
1337 if( current_stim > 210 ) {
1338 if( one_turn_in( 2_minutes ) && !has_effect( effect_downed ) ) {
1339 add_msg_if_player( m_bad, _( "Your muscles spasm!" ) );
1340 if( !has_effect( effect_downed ) ) {
1341 add_msg_if_player( m_bad, _( "You fall to the ground!" ) );
1342 add_effect( effect_downed, rng( 6_turns, 20_turns ) );
1343 }
1344 }
1345 }
1346 if( current_stim > 110 ) {
1347 if( !has_effect( effect_shakes ) && calendar::once_every( 10_minutes ) ) {
1348 add_msg( _( "You shake uncontrollably." ) );
1349 add_effect( effect_shakes, 15_minutes + 1_turns );
1350 }
1351 }
1352 if( current_stim > 75 ) {
1353 if( calendar::once_every( 5_minutes ) && !has_effect( effect_nausea ) ) {
1354 add_msg( _( "You feel nauseous…" ) );
1355 add_effect( effect_nausea, 5_minutes );
1356 }
1357 }
1358
1359 //stim -200 or painkillers 240 kills
1360 if( current_stim < -160 || get_painkiller() > 200 ) {
1361 if( one_turn_in( 3_minutes ) && !in_sleep_state() ) {
1362 add_msg_if_player( m_bad, _( "You black out!" ) );
1363 const time_duration dur = rng( 30_minutes, 60_minutes );
1364 add_effect( effect_downed, dur );
1365 fall_asleep( dur );
1366 }
1367 }
1368 if( current_stim < -60 || get_painkiller() > 130 ) {
1369 if( calendar::once_every( 10_minutes ) ) {
1370 add_msg( m_warning, _( "You feel tired…" ) );
1371 mod_fatigue( rng( 1, 2 ) );
1372 }
1373 }
1374}
static const efftype_id effect_nausea("nausea")

References _, Creature::add_effect(), add_msg(), Creature::add_msg_if_player(), effect_downed, effect_nausea, effect_shakes, fall_asleep(), get_painkiller(), Creature::has_effect(), in_sleep_state(), m_bad, m_warning, mod_fatigue(), calendar::once_every(), one_turn_in(), and rng().

Referenced by suffer().

◆ suffer_from_sunburn()

void Character::suffer_from_sunburn ( )
private

Definition at line 806 of file suffer.cpp.

807{
809 return;
810 }
811
812 std::string sunlight_effect;
814 // Albinism and datura have the same effects, once per minute on average
815 if( !one_turn_in( 1_minutes ) ) {
816 return;
817 }
818 sunlight_effect = _( "The sunlight is really irritating" );
819 } else if( has_trait( trait_SUNBURN ) ) {
820 // Sunburn effects occur about 3 times per minute
821 if( !one_turn_in( 20_seconds ) ) {
822 return;
823 }
824 sunlight_effect = _( "The sunlight burns" );
825 }
826
827 // Sunglasses can keep the sun off the eyes.
828 if( !has_bionic( bio_sunglasses ) &&
829 !( wearing_something_on( bodypart_id( "eyes" ) ) &&
831 add_msg_if_player( m_bad, _( "%s your eyes." ), sunlight_effect );
832 // Pain (1/60) or loss of focus (59/60)
833 if( one_turn_in( 1_minutes ) ) {
834 mod_pain( 1 );
835 } else {
836 focus_pool --;
837 }
838 }
839 // Umbrellas can keep the sun off the skin
840 if( weapon.has_flag( "RAIN_PROTECT" ) ) {
841 return;
842 }
843
844 std::map<bodypart_id, float> bp_exposure = bodypart_exposure();
845
846 // Minimum exposure threshold for pain
847 const float MIN_EXPOSURE = 0.01f;
848 // Count how many body parts are above the threshold
849 int count_affected_bp = 0;
850 // Get the most exposed body part, and how exposed it is. This is to tell the player what body
851 // part is most irritated by sun, so they know what needs to be covered up better.
852 bodypart_id most_exposed_bp;
853 float max_exposure = 0.0f;
854 // Check each bodypart with exposure above the minimum
855 for( const std::pair<const bodypart_id, float> &bp_exp : bp_exposure ) {
856 const float exposure = bp_exp.second;
857 // Skip minimally-exposed parts, and skip the eyes (handled by sunglasses)
858 if( exposure <= MIN_EXPOSURE || bp_exp.first == bodypart_id( "eyes" ) ) {
859 continue;
860 }
861 ++count_affected_bp;
862 if( exposure > max_exposure ) {
863 max_exposure = exposure;
864 most_exposed_bp = bp_exp.first;
865 }
866 }
867
868 // If all body parts are protected, there is no suffering
869 if( count_affected_bp == 0 || !most_exposed_bp ) {
870 return;
871 }
872
873 // Check if both arms/legs are affected
874 int count_limbs = 1;
875 const bodypart_id &other_bp = most_exposed_bp->opposite_part;
876 const bodypart_id &other_bp_rev = other_bp->opposite_part;
877 // If these are different, we have a left/right part like a leg or arm.
878 // If same, it's a central body part with no opposite, like head or torso.
879 // Only used to generate a simpler message when both arms or both legs are affected.
880 if( other_bp != other_bp_rev ) {
881 const auto found = bp_exposure.find( other_bp );
882 // Is opposite part exposed?
883 if( found != bp_exposure.end() && found->second > MIN_EXPOSURE ) {
884 ++count_limbs;
885 }
886 }
887 // Get singular or plural body part name; append "and other body parts" if appropriate
888 std::string bp_name = body_part_name( most_exposed_bp, count_limbs );
889 if( count_affected_bp == count_limbs ) {
890 add_msg_if_player( m_bad, _( "%s your %s." ), sunlight_effect, bp_name );
891 } else {
892 add_msg_if_player( m_bad, _( "%s your %s and other body parts." ), sunlight_effect,
893 bp_name );
894 }
895
896 // Wake up from skin irritation/burning
897 if( has_effect( effect_sleep ) ) {
898 wake_up();
899 }
900
901 // Solar Sensitivity (SUNBURN) trait causes injury to exposed parts
902 if( has_trait( trait_SUNBURN ) ) {
903 mod_pain( 1 );
904 // Check exposure of all body parts
905 for( const std::pair<const bodypart_id, float> &bp_exp : bp_exposure ) {
906 const bodypart_id &this_part = bp_exp.first;
907 const float exposure = bp_exp.second;
908 // Skip parts with adequate protection
909 if( exposure <= MIN_EXPOSURE ) {
910 continue;
911 }
912 // Don't damage eyes directly, since it takes from head HP (in other words, your head
913 // won't be destroyed if only your eyes are exposed).
914 if( this_part == bodypart_id( "eyes" ) ) {
915 continue;
916 }
917 // Exposure percentage determines likelihood of injury
918 // 10% exposure is 10% chance of injury, naked = 100% chance
919 if( x_in_y( exposure, 1.0 ) ) {
920 // Because hands and feet share an HP pool with arms and legs, and the mouth shares
921 // an HP pool with the head, those parts take an unfair share of damage in relation
922 // to the torso, which only has one part. Increase torso damage to balance this.
923 if( this_part == bodypart_id( "torso" ) ) {
924 apply_damage( nullptr, this_part, 2 );
925 } else {
926 apply_damage( nullptr, this_part, 1 );
927 }
928 }
929 }
930 } else {
931 // Albinism/datura causes pain (1/60) or focus loss (59/60)
932 if( one_turn_in( 1_minutes ) ) {
933 mod_pain( 1 );
934 } else {
935 focus_pool --;
936 }
937 }
938}
std::map< bodypart_id, float > bodypart_exposure()
Map body parts to their total exposure, from 0.0 (fully covered) to 1.0 (buck naked).
Definition: suffer.cpp:779
static const trait_id trait_ALBINO("ALBINO")
static const std::string flag_BLIND("BLIND")
static const trait_id trait_SUNBURN("SUNBURN")
static const std::string flag_SUN_GLASSES("SUN_GLASSES")
static const bionic_id bio_sunglasses("bio_sunglasses")

References _, Creature::add_msg_if_player(), apply_damage(), bio_sunglasses, body_part_name(), bodypart_exposure(), effect_datura, effect_sleep, flag_BLIND(), flag_SUN_GLASSES(), focus_pool, has_bionic(), Creature::has_effect(), item::has_flag(), has_trait(), m_bad, Creature::mod_pain(), one_turn_in(), trait_ALBINO, trait_SUNBURN, wake_up(), weapon, wearing_something_on(), worn_with_flag(), and x_in_y().

Referenced by suffer_in_sunlight().

◆ suffer_in_sunlight()

void Character::suffer_in_sunlight ( )
private

Definition at line 714 of file suffer.cpp.

715{
716 double sleeve_factor = armwear_factor();
717 const bool has_hat = wearing_something_on( bodypart_id( "head" ) );
718 const bool leafy = has_trait( trait_LEAVES ) || has_trait( trait_LEAVES2 ) ||
720 const bool leafier = has_trait( trait_LEAVES2 ) || has_trait( trait_LEAVES3 );
721 const bool leafiest = has_trait( trait_LEAVES3 );
722 int sunlight_nutrition = 0;
723 if( leafy && g->m.is_outside( pos() ) && ( g->light_level( pos().z ) >= 40 ) ) {
724 const float weather_factor = ( get_weather().weather_id->sun_intensity >=
725 sun_intensity_type::normal ) ? 1.0 : 0.5;
726 const int player_local_temp = get_weather().get_temperature( pos() );
727 int flux = ( player_local_temp - 65 ) / 2;
728 if( !has_hat ) {
729 sunlight_nutrition += ( 100 + flux ) * weather_factor;
730 }
731 if( leafier ) {
732 int rate = ( ( 100 * sleeve_factor ) + flux ) * 2;
733 sunlight_nutrition += ( rate * ( leafiest ? 2 : 1 ) ) * weather_factor;
734 }
735 }
736
737 if( x_in_y( sunlight_nutrition, 18000 ) ) {
738 vitamin_mod( vitamin_id( "vitA" ), 1, true );
739 vitamin_mod( vitamin_id( "vitC" ), 1, true );
740 }
741
742 if( x_in_y( sunlight_nutrition, 12000 ) ) {
743 mod_stored_kcal( 10 );
744 stomach.ate();
745 }
746
747 if( !g->is_in_sunlight( pos() ) ) {
748 return;
749 }
750
753 }
754
756 get_weather().weather_id->sun_intensity >= sun_intensity_type::high ) {
757 mod_str_bonus( -1 );
758 mod_dex_bonus( -1 );
759 add_miss_reason( _( "The sunlight distracts you." ), 1 );
760 mod_int_bonus( -1 );
761 mod_per_bonus( -1 );
762 }
763 if( has_trait( trait_TROGLO2 ) ) {
764 mod_str_bonus( -1 );
765 mod_dex_bonus( -1 );
766 add_miss_reason( _( "The sunlight distracts you." ), 1 );
767 mod_int_bonus( -1 );
768 mod_per_bonus( -1 );
769 }
770 if( has_trait( trait_TROGLO3 ) ) {
771 mod_str_bonus( -4 );
772 mod_dex_bonus( -4 );
773 add_miss_reason( _( "You can't stand the sunlight!" ), 4 );
774 mod_int_bonus( -4 );
775 mod_per_bonus( -4 );
776 }
777}
void suffer_from_sunburn()
Definition: suffer.cpp:806
double armwear_factor() const
Same as footwear factor, but for arms.
Definition: character.cpp:8937
weather_type_id weather_id
Definition: weather.h:193
sun_intensity_type sun_intensity
Definition: weather_type.h:121
static const trait_id trait_LEAVES("LEAVES")
static const trait_id trait_TROGLO3("TROGLO3")
static const trait_id trait_LEAVES2("LEAVES2")
static const trait_id trait_TROGLO("TROGLO")
static const trait_id trait_TROGLO2("TROGLO2")
static const trait_id trait_LEAVES3("LEAVES3")

References _, add_miss_reason(), armwear_factor(), stomach_contents::ate(), effect_datura, g, weather_manager::get_temperature(), get_weather(), Creature::has_effect(), has_trait(), high, mod_dex_bonus(), mod_int_bonus(), mod_per_bonus(), mod_stored_kcal(), mod_str_bonus(), normal, pos(), stomach, suffer_from_sunburn(), weather_type::sun_intensity, trait_ALBINO, trait_LEAVES, trait_LEAVES2, trait_LEAVES3, trait_SUNBURN, trait_TROGLO, trait_TROGLO2, trait_TROGLO3, vitamin_mod(), wearing_something_on(), weather_manager::weather_id, and x_in_y().

Referenced by suffer().

◆ suffer_mutation_power()

void Character::suffer_mutation_power ( const mutation_branch mdata,
Character::trait_data tdata 
)
private

Definition at line 202 of file suffer.cpp.

204{
205 if( tdata.powered && tdata.charge > 0 ) {
206 // Already-on units just lose a bit of charge
207 tdata.charge--;
208 } else {
209 // Not-on units, or those with zero charge, have to pay the power cost
210 if( mdata.cooldown > 0 ) {
211 tdata.powered = true;
212 tdata.charge = mdata.cooldown - 1;
213 }
214 if( mdata.hunger ) {
215 // does not directly modify hunger, but burns kcal
216 mod_stored_nutr( mdata.cost );
219 _( "You're too malnourished to keep your %s going." ),
220 mdata.name() );
221 tdata.powered = false;
222 }
223 }
224 if( mdata.thirst ) {
225 mod_thirst( mdata.cost );
226 // Well into Dehydrated
229 _( "You're too dehydrated to keep your %s going." ),
230 mdata.name() );
231 tdata.powered = false;
232 }
233 }
234 if( mdata.fatigue ) {
235 mod_fatigue( mdata.cost );
236 // Exhausted
239 _( "You're too exhausted to keep your %s going." ),
240 mdata.name() );
241 tdata.powered = false;
242 }
243 }
244 if( !tdata.powered ) {
245 apply_mods( mdata.id, false );
246 }
247 }
248}
virtual void mod_stored_nutr(int nnutr)
Definition: character.cpp:4320
constexpr float underweight
int charge
Time (in turns) until the mutation increase hunger/thirst/fatigue according to its cost (mutation_bra...
Definition: character.h:2052

References _, Creature::add_msg_if_player(), apply_mods(), bmi(), Character::trait_data::charge, mutation_branch::cooldown, mutation_branch::cost, dehydrated, exhausted, mutation_branch::fatigue, get_fatigue(), get_thirst(), mutation_branch::hunger, mutation_branch::id, m_warning, mod_fatigue(), mod_stored_nutr(), mod_thirst(), mutation_branch::name(), Character::trait_data::powered, mutation_branch::thirst, and character_weight_category::underweight.

Referenced by suffer().

◆ suffer_water_damage()

void Character::suffer_water_damage ( const mutation_branch mdata)
private

suffer() subcalls

Definition at line 182 of file suffer.cpp.

183{
184 for( const std::pair<const bodypart_str_id, bodypart> &elem : get_body() ) {
185 const float wetness_percentage = static_cast<float>( body_wetness[elem.first->token] ) /
186 drench_capacity[elem.first->token];
187 const int dmg = mdata.weakness_to_water * wetness_percentage;
188 if( dmg > 0 ) {
189 apply_damage( nullptr, elem.first, dmg );
190 add_msg_player_or_npc( m_bad, _( "Your %s is damaged by the water." ),
191 _( "<npcname>'s %s is damaged by the water." ),
192 body_part_name( elem.first ) );
193 } else if( dmg < 0 && elem.second.is_at_max_hp() ) {
194 heal( elem.first, std::abs( dmg ) );
195 add_msg_player_or_npc( m_good, _( "Your %s is healed by the water." ),
196 _( "<npcname>'s %s is healed by the water." ),
197 body_part_name( elem.first ) );
198 }
199 }
200}
int weakness_to_water
maximum damage dealt by water every minute when wet.
Definition: mutation.h:166

References _, Creature::add_msg_player_or_npc(), apply_damage(), body_part_name(), body_wetness, drench_capacity, Creature::get_body(), heal(), m_bad, m_good, and mutation_branch::weakness_to_water.

Referenced by suffer().

◆ suffer_while_awake()

void Character::suffer_while_awake ( int  current_stim)
private

Definition at line 300 of file suffer.cpp.

301{
303 ( weight_carried() > 4 * weight_capacity() ) ) {
304 if( has_effect( effect_downed ) ) {
305 add_effect( effect_downed, 1_turns, num_bp, 0 );
306 } else {
307 add_effect( effect_downed, 2_turns, num_bp, 0 );
308 }
309 }
312 }
316 }
317
319 if( one_turn_in( 8_hours ) ) {
320 add_msg( m_bad,
321 _( "You're suddenly overcome with the urge to sleep and you pass out." ) );
322 fall_asleep( 20_minutes );
323 }
324 }
325
327 if( current_stim > 50 && one_in( to_turns<int>( 30_minutes ) - ( current_stim * 6 ) ) ) {
328 add_effect( effect_shakes, 30_minutes + 1_turns * current_stim );
329 } else if( ( get_kcal_percent() < 0.95f ) &&
330 one_turn_in( 60_minutes - 1_seconds * ( max_stored_kcal() - get_stored_kcal() ) ) ) {
331 add_effect( effect_shakes, 40_minutes );
332 }
333 }
334
335 if( has_trait( trait_MOODSWINGS ) && one_turn_in( 6_hours ) ) {
336 if( rng( 1, 20 ) > 9 ) {
337 // 55% chance
338 add_morale( MORALE_MOODSWING, -100, -500 );
339 } else {
340 // 45% chance
341 add_morale( MORALE_MOODSWING, 100, 500 );
342 }
343 }
344
345 if( has_trait( trait_VOMITOUS ) && one_turn_in( 7_hours ) ) {
346 vomit();
347 }
348
349 if( has_trait( trait_SHOUT1 ) && one_turn_in( 6_hours ) ) {
350 shout();
351 }
352 if( has_trait( trait_SHOUT2 ) && one_turn_in( 4_hours ) ) {
353 shout();
354 }
355 if( has_trait( trait_SHOUT3 ) && one_turn_in( 3_hours ) ) {
356 shout();
357 }
358 if( has_trait( trait_M_SPORES ) && one_turn_in( 4_hours ) ) {
359 spores();
360 }
361 if( has_trait( trait_M_BLOSSOMS ) && one_turn_in( 3_hours ) ) {
362 blossoms();
363 }
364}
void suffer_from_chemimbalance()
Definition: suffer.cpp:366
void suffer_from_schizophrenia()
Definition: suffer.cpp:429
@ AEP_SCHIZO
Definition: enums.h:128
const morale_type MORALE_MOODSWING("morale_moodswing")
static const trait_id trait_JITTERY("JITTERY")
static const trait_id trait_SHOUT1("SHOUT1")
static const trait_id trait_NARCOLEPTIC("NARCOLEPTIC")
static const efftype_id effect_took_thorazine("took_thorazine")
static const trait_id trait_SHOUT2("SHOUT2")
static const trait_id trait_VOMITOUS("VOMITOUS")
static const trait_id trait_DEBUG_STORAGE("DEBUG_STORAGE")
static const trait_id trait_CHEMIMBALANCE("CHEMIMBALANCE")
static const trait_id trait_M_BLOSSOMS("M_BLOSSOMS")
static const trait_id trait_SHOUT3("SHOUT3")
static const trait_id trait_SCHIZOPHRENIC("SCHIZOPHRENIC")
static const trait_id trait_M_SPORES("M_SPORES")
static const trait_id trait_MOODSWINGS("MOODSWINGS")

References _, Creature::add_effect(), add_morale(), add_msg(), AEP_SCHIZO, blossoms(), effect_downed, effect_shakes, effect_took_thorazine, fall_asleep(), get_kcal_percent(), get_stored_kcal(), has_artifact_with(), Creature::has_effect(), has_trait(), m_bad, max_stored_kcal(), MORALE_MOODSWING, num_bp, one_in(), one_turn_in(), rng(), shout(), spores(), suffer_from_chemimbalance(), suffer_from_schizophrenia(), trait_CHEMIMBALANCE, trait_DEBUG_STORAGE, trait_JITTERY, trait_M_BLOSSOMS, trait_M_SPORES, trait_MOODSWINGS, trait_NARCOLEPTIC, trait_SCHIZOPHRENIC, trait_SHOUT1, trait_SHOUT2, trait_SHOUT3, trait_VOMITOUS, vomit(), weight_capacity(), and weight_carried().

Referenced by suffer().

◆ suffer_while_underwater()

void Character::suffer_while_underwater ( )
private

Definition at line 250 of file suffer.cpp.

251{
253 oxygen--;
254 }
255 if( oxygen < 12 && worn_with_flag( "REBREATHER" ) ) {
256 oxygen += 12;
257 }
258 if( oxygen <= 5 ) {
259 if( has_bionic( bio_gills ) && get_power_level() >= 25_kJ ) {
260 oxygen += 5;
261 mod_power_level( -25_kJ );
262 } else {
263 add_msg_if_player( m_bad, _( "You're drowning!" ) );
264 apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 4 ) );
265 }
266 }
267 if( has_trait( trait_FRESHWATEROSMOSIS ) && !g->m.has_flag_ter( "SALT_WATER", pos() ) &&
269 mod_thirst( -1 );
270 }
271}
static const trait_id trait_FRESHWATEROSMOSIS("FRESHWATEROSMOSIS")
static const trait_id trait_GILLS_CEPH("GILLS_CEPH")
static const trait_id trait_GILLS("GILLS")

References _, Creature::add_msg_if_player(), apply_damage(), bio_gills, g, get_power_level(), get_thirst(), has_bionic(), has_trait(), m_bad, mod_power_level(), mod_thirst(), oxygen, pos(), rng(), trait_FRESHWATEROSMOSIS, trait_GILLS, trait_GILLS_CEPH, turgid, and worn_with_flag().

Referenced by suffer().

◆ suffer_without_sleep()

void Character::suffer_without_sleep ( int  sleep_deprivation)
private

Definition at line 1376 of file suffer.cpp.

1377{
1378 if( has_effect( effect_meth ) ) {
1379 return;
1380 }
1381 // redo as a snippet?
1383 if( one_turn_in( 50_minutes ) ) {
1384 switch( dice( 1, 4 ) ) {
1385 default:
1386 case 1:
1387 add_msg_player_or_npc( m_warning, _( "You tiredly rub your eyes." ),
1388 _( "<npcname> tiredly rubs their eyes." ) );
1389 break;
1390 case 2:
1391 add_msg_player_or_npc( m_warning, _( "You let out a small yawn." ),
1392 _( "<npcname> lets out a small yawn." ) );
1393 break;
1394 case 3:
1395 add_msg_player_or_npc( m_warning, _( "You stretch your back." ),
1396 _( "<npcname> stretches their back." ) );
1397 break;
1398 case 4:
1399 add_msg_player_or_npc( m_warning, _( "You feel mentally tired." ),
1400 _( "<npcname> lets out a huge yawn." ) );
1401 break;
1402 }
1403 }
1404 }
1405 // Minor discomfort
1407 if( one_turn_in( 75_minutes ) ) {
1408 add_msg_if_player( m_warning, _( "You feel lightheaded for a moment." ) );
1409 moves -= 10;
1410 }
1411 if( one_turn_in( 100_minutes ) ) {
1412 add_msg_if_player( m_warning, _( "Your muscles spasm uncomfortably." ) );
1413 mod_pain( 2 );
1414 }
1415 if( !has_effect( effect_visuals ) && one_turn_in( 150_minutes ) ) {
1416 add_msg_if_player( m_warning, _( "Your vision blurs a little." ) );
1417 add_effect( effect_visuals, rng( 1_minutes, 5_minutes ) );
1418 }
1419 }
1420 // Slight disability
1422 if( one_turn_in( 75_minutes ) ) {
1423 add_msg_if_player( m_bad, _( "Your mind lapses into unawareness briefly." ) );
1424 moves -= rng( 20, 80 );
1425 }
1426 if( one_turn_in( 125_minutes ) ) {
1427 add_msg_if_player( m_bad, _( "Your muscles ache in stressfully unpredictable ways." ) );
1428 mod_pain( rng( 2, 10 ) );
1429 }
1430 if( one_turn_in( 5_hours ) ) {
1431 add_msg_if_player( m_bad, _( "You have a distractingly painful headache." ) );
1432 mod_pain( rng( 10, 25 ) );
1433 }
1434 }
1435 // Major disability, high chance of passing out also relevant
1437 if( !has_effect( effect_nausea ) && one_turn_in( 500_minutes ) ) {
1438 add_msg_if_player( m_bad, _( "You feel heartburn and an acid taste in your mouth." ) );
1439 mod_pain( 5 );
1440 add_effect( effect_nausea, rng( 5_minutes, 30_minutes ) );
1441 }
1442 if( one_turn_in( 5_hours ) ) {
1443 add_msg_if_player( m_bad, _( "Your mind is so tired that you feel you can't trust "
1444 "your eyes anymore." ) );
1445 add_effect( effect_hallu, rng( 5_minutes, 60_minutes ) );
1446 }
1447 if( !has_effect( effect_shakes ) && one_turn_in( 425_minutes ) ) {
1448 add_msg_if_player( m_bad, _( "Your muscles spasm uncontrollably, and you have "
1449 "trouble keeping your balance." ) );
1450 add_effect( effect_shakes, 15_minutes );
1451 } else if( has_effect( effect_shakes ) && one_turn_in( 75_seconds ) ) {
1452 moves -= 10;
1453 add_msg_player_or_npc( m_warning, _( "Your shaking legs make you stumble." ),
1454 _( "<npcname> stumbles." ) );
1455 if( !has_effect( effect_downed ) && one_in( 10 ) ) {
1456 add_msg_player_or_npc( m_bad, _( "You fall over!" ), _( "<npcname> falls over!" ) );
1457 add_effect( effect_downed, rng( 3_turns, 10_turns ) );
1458 }
1459 }
1460 }
1461}
int dice(int number, int sides)
Definition: rng.cpp:85
static const efftype_id effect_meth("meth")

References _, Creature::add_effect(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), dice(), effect_downed, effect_hallu, effect_meth, effect_nausea, effect_shakes, effect_visuals, harmless, Creature::has_effect(), m_bad, m_warning, major, minor, Creature::mod_pain(), Creature::moves, one_in(), one_turn_in(), rng(), serious, and sleep_deprivation.

Referenced by suffer().

◆ swim_speed()

int Character::swim_speed ( ) const

Returns the player's speed for swimming across water tiles.

Strength increases swim speed bonus from PAWS Strength increases swim speed bonus from PAWS_LARGE Strength increases swim speed bonus from swim_fins Strength increases swim speed bonus from WEBBED Swimming increases swim speed Strength increases swim speed Dexterity increases swim speed

Definition at line 882 of file character.cpp.

883{
884 int ret;
885 if( is_mounted() ) {
886 monster *mon = mounted_creature.get();
887 // no difference in swim speed by monster type yet.
888 // TODO: difference in swim speed by monster type.
889 // No monsters are currently mountable and can swim, though mods may allow this.
890 if( mon->swims() ) {
891 ret = 25;
892 ret += get_weight() / 120_gram - 50 * mon->get_size();
893 return ret;
894 }
895 }
896 const auto usable = exclusive_flag_coverage( "ALLOWS_NATURAL_ATTACKS" );
897 float hand_bonus_mult = ( usable.test( bp_hand_l ) ? 0.5f : 0.0f ) +
898 ( usable.test( bp_hand_r ) ? 0.5f : 0.0f );
899
900 // base swim speed.
901 ret = ( 440 * mutation_value( "movecost_swim_modifier" ) ) + weight_carried() /
902 ( 60_gram / mutation_value( "movecost_swim_modifier" ) ) - 50 * get_skill_level( skill_swimming );
903 /** @EFFECT_STR increases swim speed bonus from PAWS */
904 if( has_trait( trait_PAWS ) ) {
905 ret -= hand_bonus_mult * ( 20 + str_cur * 3 );
906 }
907 /** @EFFECT_STR increases swim speed bonus from PAWS_LARGE */
908 if( has_trait( trait_PAWS_LARGE ) ) {
909 ret -= hand_bonus_mult * ( 20 + str_cur * 4 );
910 }
911 /** @EFFECT_STR increases swim speed bonus from swim_fins */
912 if( worn_with_flag( "FIN", bodypart_id( "foot_l" ) ) ||
913 worn_with_flag( "FIN", bodypart_id( "foot_r" ) ) ) {
914 if( worn_with_flag( "FIN", bodypart_id( "foot_l" ) ) &&
915 worn_with_flag( "FIN", bodypart_id( "foot_r" ) ) ) {
916 ret -= ( 15 * str_cur );
917 } else {
918 ret -= ( 15 * str_cur ) / 2;
919 }
920 }
921 /** @EFFECT_STR increases swim speed bonus from WEBBED */
922 if( has_trait( trait_WEBBED ) ) {
923 ret -= hand_bonus_mult * ( 60 + str_cur * 5 );
924 }
925 /** @EFFECT_SWIMMING increases swim speed */
926 ret += ( 50 - get_skill_level( skill_swimming ) * 2 ) * ( ( encumb( bp_leg_l ) + encumb(
927 bp_leg_r ) ) / 10 );
928 ret += ( 80 - get_skill_level( skill_swimming ) * 3 ) * ( encumb( bp_torso ) / 10 );
929 if( get_skill_level( skill_swimming ) < 10 ) {
930 for( auto &i : worn ) {
931 ret += i.volume() / 125_ml * ( 10 - get_skill_level( skill_swimming ) );
932 }
933 }
934 /** @EFFECT_STR increases swim speed */
935
936 /** @EFFECT_DEX increases swim speed */
937 ret -= str_cur * 6 + dex_cur * 4;
938 if( worn_with_flag( "FLOTATION" ) ) {
939 ret = std::min( ret, 400 );
940 ret = std::max( ret, 200 );
941 }
942 // If (ret > 500), we can not swim; so do not apply the underwater bonus.
943 if( underwater && ret < 500 ) {
944 ret -= 50;
945 }
946
947 // Running movement mode while swimming means faster swim style, like crawlstroke
948 if( move_mode == CMM_RUN ) {
949 ret -= 80;
950 }
951 // Crouching movement mode while swimming means slower swim style, like breaststroke
952 if( move_mode == CMM_CROUCH ) {
953 ret += 50;
954 }
955
956 if( ret < 30 ) {
957 ret = 30;
958 }
959 return ret;
960}
static const skill_id skill_swimming("swimming")
static const trait_id trait_WEBBED("WEBBED")
static const trait_id trait_PAWS_LARGE("PAWS_LARGE")
static const trait_id trait_PAWS("PAWS")
bool swims() const
Definition: monster.cpp:926

References bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, CMM_CROUCH, CMM_RUN, dex_cur, encumb(), exclusive_flag_coverage(), monster::get_size(), get_skill_level(), get_weight(), has_trait(), is_mounted(), mounted_creature, move_mode, mutation_value(), cata::hash64_detail::ret, skill_swimming, str_cur, monster::swims(), trait_PAWS, trait_PAWS_LARGE, trait_WEBBED, Creature::underwater, weight_carried(), worn, and worn_with_flag().

Referenced by avatar_action::move(), avatar_action::swim(), and game::vertical_move().

◆ switch_mutations()

void Character::switch_mutations ( const trait_id switched,
const trait_id target,
bool  start_powered 
)

Unset switched mutation and set target mutation instead.

Definition at line 184 of file mutation.cpp.

186{
187 unset_mutation( switched );
188 mutation_loss_effect( switched );
189
190 set_mutation( target );
191 my_mutations[target].powered = start_powered;
192 mutation_effect( target );
193}

References mutation_effect(), mutation_loss_effect(), my_mutations, set_mutation(), and unset_mutation().

Referenced by activate_mutation(), and deactivate_mutation().

◆ symbol()

const std::string & Character::symbol ( ) const
overridevirtual

Implements Creature.

Definition at line 514 of file character.cpp.

515{
516 static const std::string character_symbol( "@" );
517 return character_symbol;
518}

Referenced by anonymous_namespace{animation.cpp}::draw_hit_player_curses(), map_memory::load_legacy(), avatar::memorize_symbol(), mm_elem::operator==(), and mm_submap::serialize().

◆ symbol_color()

nc_color Character::symbol_color ( ) const
overridevirtual

Color's character's tile's background.

Implements Creature.

Definition at line 6124 of file character.cpp.

6125{
6126 nc_color basic = basic_symbol_color();
6127
6128 if( has_effect( effect_downed ) ) {
6129 return hilite( basic );
6130 } else if( has_effect( effect_grabbed ) ) {
6131 return cyan_background( basic );
6132 }
6133
6134 const auto &fields = get_map().field_at( pos() );
6135
6136 // Priority: electricity, fire, acid, gases
6137 bool has_elec = false;
6138 bool has_fire = false;
6139 bool has_acid = false;
6140 bool has_fume = false;
6141 for( const auto &field : fields ) {
6142 has_elec = field.first.obj().has_elec;
6143 if( has_elec ) {
6144 return hilite( basic );
6145 }
6146 has_fire = field.first.obj().has_fire;
6147 has_acid = field.first.obj().has_acid;
6148 has_fume = field.first.obj().has_fume;
6149 }
6150 if( has_fire ) {
6151 return red_background( basic );
6152 }
6153 if( has_acid ) {
6154 return green_background( basic );
6155 }
6156 if( has_fume ) {
6157 return white_background( basic );
6158 }
6159 if( in_sleep_state() ) {
6160 return hilite( basic );
6161 }
6162 return basic;
6163}
virtual nc_color basic_symbol_color() const =0
A variable sized collection of field entries on a given map square.
Definition: field.h:131
nc_color white_background(const nc_color &c)
Definition: color.cpp:521
nc_color green_background(const nc_color &c)
Definition: color.cpp:527
nc_color red_background(const nc_color &c)
Definition: color.cpp:515
nc_color cyan_background(const nc_color &c)
Definition: color.cpp:545
nc_color hilite(const nc_color &c)
Definition: color.cpp:509

References Creature::basic_symbol_color(), cyan_background(), effect_downed, effect_grabbed, map::field_at(), get_map(), green_background(), Creature::has_effect(), has_fire(), hilite(), in_sleep_state(), pos(), red_background(), and white_background().

Referenced by overmap_ui::draw_ascii(), anonymous_namespace{animation.cpp}::draw_hit_player_curses(), and game::list_monsters().

◆ temp_corrected_by_climate_control()

int Character::temp_corrected_by_climate_control ( int  temperature) const

Value of the body temperature corrected by climate control.

Definition at line 9573 of file character.cpp.

9574{
9575 const int variation = int( BODYTEMP_NORM * 0.5 );
9576 if( temperature < BODYTEMP_SCORCHING + variation &&
9577 temperature > BODYTEMP_FREEZING - variation ) {
9580 } else if( temperature > BODYTEMP_VERY_HOT ) {
9582 } else if( temperature > BODYTEMP_HOT ) {
9584 } else if( temperature < BODYTEMP_FREEZING ) {
9586 } else if( temperature < BODYTEMP_VERY_COLD ) {
9588 } else if( temperature < BODYTEMP_COLD ) {
9590 }
9591 }
9592 return temperature;
9593}

References BODYTEMP_COLD, BODYTEMP_FREEZING, BODYTEMP_HOT, BODYTEMP_NORM, BODYTEMP_SCORCHING, BODYTEMP_VERY_COLD, and BODYTEMP_VERY_HOT.

Referenced by update_bodytemp().

◆ temp_equalizer()

void Character::temp_equalizer ( const bodypart_id bp1,
const bodypart_id bp2 
)

Equalizes heat between body parts.

Definition at line 5693 of file character.cpp.

5694{
5695 // Body heat is moved around.
5696 // If bp1 is warmer, it will lose heat
5697 int diff = static_cast<int>( ( temp_cur[bp2->token] - temp_cur[bp1->token] ) * 0.001 );
5698 temp_cur[bp1->token] += diff;
5699 temp_cur[bp2->token] -= diff;
5700}

References temp_cur.

Referenced by update_bodytemp().

◆ throw_range()

int Character::throw_range ( const item it) const

Maximum thrown range with a given item, taking all active effects into account.

Strength determines maximum weight that can be thrown Strength increases throwing range, vs item weight (high or low) Strength caps throwing range Throw caps throwing range

Definition at line 6282 of file character.cpp.

6283{
6284 if( it.is_null() ) {
6285 return -1;
6286 }
6287
6288 item tmp = it;
6289
6290 if( tmp.count_by_charges() && tmp.charges > 1 ) {
6291 tmp.charges = 1;
6292 }
6293
6294 /** @EFFECT_STR determines maximum weight that can be thrown */
6295 if( ( tmp.weight() / 113_gram ) > static_cast<int>( str_cur * 15 ) ) {
6296 return 0;
6297 }
6298 // Increases as weight decreases until 150 g, then decreases again
6299 /** @EFFECT_STR increases throwing range, vs item weight (high or low) */
6300 int str_override = str_cur;
6301 if( is_mounted() ) {
6302 auto mons = mounted_creature.get();
6303 str_override = mons->mech_str_addition() != 0 ? mons->mech_str_addition() : str_cur;
6304 }
6305 int ret = ( str_override * 10 ) / ( tmp.weight() >= 150_gram ? tmp.weight() / 113_gram : 10 -
6306 static_cast<int>(
6307 tmp.weight() / 15_gram ) );
6308 ret -= tmp.volume() / 1_liter;
6309 static const std::set<material_id> affected_materials = { material_id( "iron" ), material_id( "steel" ) };
6310 if( has_active_bionic( bio_railgun ) && tmp.made_of_any( affected_materials ) ) {
6311 ret *= 2;
6312 }
6313 if( ret < 1 ) {
6314 return 1;
6315 }
6316 // Cap at double our strength + skill
6317 /** @EFFECT_STR caps throwing range */
6318
6319 /** @EFFECT_THROW caps throwing range */
6320 if( ret > str_override * 3 + get_skill_level( skill_throw ) ) {
6321 return str_override * 3 + get_skill_level( skill_throw );
6322 }
6323
6324 return ret;
6325}
static const bionic_id bio_railgun("bio_railgun")
static const skill_id skill_throw("throw")

References bio_railgun, item::charges, item::count_by_charges(), get_skill_level(), has_active_bionic(), is_mounted(), item::is_null(), item::made_of_any(), mounted_creature, cata::hash64_detail::ret, skill_throw, str_cur, item::volume(), and item::weight().

Referenced by npc::alt_attack(), target_handler::mode_throw(), and avatar_action::plthrow().

◆ toggle_trait()

void Character::toggle_trait ( const trait_id trait_)

Toggles a trait on the player and in their mutation list.

Definition at line 127 of file mutation.cpp.

128{
129 // Take copy of argument because it might be a reference into a container
130 // we're about to erase from.
131 // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
132 const trait_id trait = trait_;
133 const auto titer = my_traits.find( trait );
134 const auto miter = my_mutations.find( trait );
135 // These shouldn't be inlined, otherwise the sync check uses invalid iterators
136 bool no_trait = titer == my_traits.end();
137 bool no_mutation = miter == my_mutations.end();
138 if( no_trait ) {
139 my_traits.insert( trait );
140 } else {
141 my_traits.erase( titer );
142 }
143 if( no_trait != no_mutation ) {
144 debugmsg( "my_traits and my_mutations were out of sync for %s\n", trait.str() );
145 return;
146 }
147 if( no_mutation ) {
148 set_mutation( trait );
149 } else {
150 unset_mutation( trait );
151 }
152}

References debugmsg, my_mutations, my_traits, set_mutation(), string_id< T >::str(), and unset_mutation().

Referenced by add_traits(), clear_mutations(), avatar::create(), wish_mutate_callback::key(), avatar::randomize(), npc::randomize(), reset_scenario(), set_profession(), set_traits(), and gun_actor::shoot().

◆ trait_by_invlet()

trait_id Character::trait_by_invlet ( int  ch) const

Returns the trait id with the given invlet, or an empty string if no trait has that invlet.

Definition at line 629 of file mutation.cpp.

630{
631 for( const std::pair<const trait_id, trait_data> &mut : my_mutations ) {
632 if( mut.second.key == ch ) {
633 return mut.first;
634 }
635 }
636 return trait_id::NULL_ID();
637}

References my_mutations, and string_id< mutation_branch >::NULL_ID().

Referenced by player::power_mutations_ui().

◆ unarmed_attack()

bool Character::unarmed_attack ( ) const

True if unarmed or wielding a weapon with the UNARMED_WEAPON flag.

Definition at line 150 of file melee.cpp.

151{
152 const item &weap = used_weapon();
153 return weap.is_null() || weap.has_flag( "UNARMED_WEAPON" );
154}

References item::has_flag(), item::is_null(), and used_weapon().

Referenced by mattack::copbot(), has_weapon(), conditional_t< T >::set_can_stow_weapon(), and conditional_t< T >::set_has_weapon().

◆ unimpaired_range()

int Character::unimpaired_range ( ) const

Returns the player maximum vision range factoring in mutations, diseases, and other effects.

Definition at line 743 of file character.cpp.

744{
745 return std::min( sight_max, 60 );
746}

References sight_max.

Referenced by sees().

◆ uninstall_bionic() [1/2]

bool Character::uninstall_bionic ( const bionic target_cbm,
monster installer,
player patient,
float  adjusted_skill 
)

Used by monster to perform surgery.

Definition at line 2091 of file bionics.cpp.

2093{
2094 if( installer.ammo[itype_anesthetic] <= 0 ) {
2095 if( g->u.sees( installer ) ) {
2096 add_msg( _( "The %s's anesthesia kit looks empty." ), installer.name() );
2097 }
2098 return false;
2099 }
2100
2101 const itype_id itemtype = target_cbm.info().itype();
2102 int difficulty = itemtype.is_valid() ? itemtype->bionic->difficulty : BIONIC_NOITEM_DIFFICULTY;
2103 int chance_of_success = bionic_manip_cos( adjusted_skill, difficulty + 2 );
2104 int success = chance_of_success - rng( 1, 100 );
2105
2106 const time_duration duration = difficulty * 20_minutes;
2107 // don't stack up the effect
2108 if( !installer.has_effect( effect_operating ) ) {
2109 installer.add_effect( effect_operating, duration + 5_turns );
2110 }
2111
2112 if( patient.is_player() ) {
2113 add_msg( m_bad,
2114 _( "You feel a tiny pricking sensation in your right arm, and lose all sensation before abruptly blacking out." ) );
2115 } else if( g->u.sees( installer ) ) {
2116 add_msg( m_bad,
2117 _( "The %1$s gently inserts a syringe into %2$s's arm and starts injecting something while holding them down." ),
2118 installer.name(), patient.disp_name() );
2119 }
2120
2121 installer.ammo[itype_anesthetic] -= 1;
2122
2123 patient.add_effect( effect_narcosis, duration );
2124 patient.add_effect( effect_sleep, duration );
2125
2126 if( patient.is_player() ) {
2127 add_msg( _( "You fall asleep and %1$s starts operating." ), installer.disp_name() );
2128 } else if( g->u.sees( patient ) ) {
2129 add_msg( _( "%1$s falls asleep and %2$s starts operating." ), patient.disp_name(),
2130 installer.disp_name() );
2131 }
2132
2133 if( success > 0 ) {
2134
2135 if( patient.is_player() ) {
2136 add_msg( m_neutral, _( "Your parts are jiggled back into their familiar places." ) );
2137 add_msg( m_mixed, _( "Successfully removed %s." ), target_cbm.info().name );
2138 } else if( patient.is_npc() && g->u.sees( patient ) ) {
2139 add_msg( m_neutral, _( "%s's parts are jiggled back into their familiar places." ),
2140 patient.disp_name() );
2141 add_msg( m_mixed, _( "Successfully removed %s." ), target_cbm.info().name );
2142 }
2143
2144 // remove power bank provided by bionic
2145 patient.mod_max_power_level( -target_cbm.info().capacity );
2146 patient.remove_bionic( target_cbm.id );
2147 const itype_id iid = itemtype.is_valid() ? itemtype : itype_burnt_out_bionic;
2149 cbm.faults.emplace( fault_bionic_nonsterile );
2150 get_map().add_item( patient.pos(), cbm );
2151 } else {
2152 bionics_uninstall_failure( installer, patient, difficulty, success, adjusted_skill );
2153 }
2154
2155 return false;
2156}
static const efftype_id effect_sleep("sleep")
static const efftype_id effect_operating("operating")
static const itype_id itype_anesthetic("anesthetic")
std::map< itype_id, int > ammo
Definition: monster.h:514
std::string disp_name(bool possessive=false, bool capitalize_first=false) const override
Definition: monster.cpp:536
bool is_npc() const override
Definition: player.h:122

References _, Creature::add_effect(), monster::add_effect(), map::add_item(), add_msg(), monster::ammo, itype::bionic, bionic_manip_cos(), BIONIC_NOITEM_DIFFICULTY, bionics_uninstall_failure(), bionic_data::capacity, disp_name(), monster::disp_name(), effect_narcosis, effect_operating, effect_sleep, fault_bionic_nonsterile, item::faults, g, get_map(), Creature::has_effect(), bionic::id, bionic::info(), player::is_npc(), player::is_player(), string_id< T >::is_valid(), bionic_data::itype(), itype_anesthetic, itype_burnt_out_bionic, m_bad, m_mixed, m_neutral, mod_max_power_level(), bionic_data::name, monster::name(), pos(), remove_bionic(), rng(), calendar::start_of_cataclysm, and behavior::success.

◆ uninstall_bionic() [2/2]

bool Character::uninstall_bionic ( const bionic_id b_id,
player installer,
bool  autodoc = false,
int  skill_level = -1 
)

Initialize all the values needed to start the operation player_activity.

Definition at line 1986 of file bionics.cpp.

1988{
1989 // If malfunctioning bionics doesn't have associated item it gets predefined difficulty
1990 int difficulty = BIONIC_NOITEM_DIFFICULTY;
1991 if( b_id->itype().is_valid() ) {
1992 const itype *type = &*b_id->itype();
1993 if( type->bionic ) {
1994 difficulty = type->bionic->difficulty;
1995 }
1996 }
1997
1998 // removal of bionics adds +2 difficulty over installation
1999 float adjusted_skill;
2000 int pl_skill;
2001 if( autodoc ) {
2002 adjusted_skill = installer.bionics_adjusted_skill( skill_firstaid,
2005 skill_level );
2006 pl_skill = installer.bionics_pl_skill( skill_firstaid,
2009 skill_level );
2010 } else {
2011 adjusted_skill = installer.bionics_adjusted_skill( skill_electronics,
2014 skill_level );
2015 pl_skill = installer.bionics_pl_skill( skill_electronics,
2018 skill_level );
2019 }
2020
2021 int chance_of_success = bionic_manip_cos( adjusted_skill, difficulty + 2 );
2022
2023 // Surgery is imminent, retract claws or blade if active
2024 for( size_t i = 0; i < installer.my_bionics->size(); i++ ) {
2025 const bionic &bio = ( *installer.my_bionics )[ i ];
2026 if( bio.powered && bio.info().has_flag( flag_BIONIC_WEAPON ) ) {
2027 installer.deactivate_bionic( i );
2028 }
2029 }
2030
2031 int success = chance_of_success - rng( 1, 100 );
2032 if( installer.has_trait( trait_DEBUG_BIONICS ) ) {
2033 perform_uninstall( b_id, difficulty, success, b_id->capacity, pl_skill );
2034 return true;
2035 }
2036 assign_activity( ACT_OPERATION, to_moves<int>( difficulty * 20_minutes ) );
2037
2038 activity.values.push_back( difficulty );
2039 activity.values.push_back( success );
2040 activity.values.push_back( units::to_kilojoule( b_id->capacity ) );
2041 activity.values.push_back( pl_skill );
2042 activity.str_values.push_back( "uninstall" );
2043 activity.str_values.push_back( b_id.str() );
2044 activity.str_values.push_back( "" ); // installer_name is unused for uninstall
2045 if( autodoc ) {
2046 activity.str_values.push_back( "true" );
2047 } else {
2048 activity.str_values.push_back( "false" );
2049 }
2050 for( const std::pair<const bodypart_str_id, int> &elem : b_id->occupied_bodyparts ) {
2051 add_effect( effect_under_op, difficulty * 20_minutes, elem.first->token, difficulty );
2052 }
2053
2054 return true;
2055}
void perform_uninstall(bionic_id bid, int difficulty, int success, const units::energy &power_lvl, int pl_skill)
Succes or failure of removal happens here.
Definition: bionics.cpp:2057

References ACT_OPERATION, activity, Creature::add_effect(), assign_activity(), iexamine::autodoc(), bionic_manip_cos(), BIONIC_NOITEM_DIFFICULTY, bionics_adjusted_skill(), bionics_pl_skill(), bionic_data::capacity, deactivate_bionic(), effect_under_op, flag_BIONIC_WEAPON, bionic_data::has_flag(), has_trait(), bionic::info(), string_id< T >::is_valid(), bionic_data::itype(), my_bionics, bionic_data::occupied_bodyparts, perform_uninstall(), bionic::powered, rng(), skill_computer, skill_electronics, skill_firstaid, skill_mechanics, string_id< T >::str(), player_activity::str_values, behavior::success, units::to_kilojoule(), trait_DEBUG_BIONICS, type, and player_activity::values.

Referenced by iexamine::autodoc().

◆ unset_mutation()

void Character::unset_mutation ( const trait_id trait_)

Definition at line 167 of file mutation.cpp.

168{
169 // Take copy of argument because it might be a reference into a container
170 // we're about to erase from.
171 // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
172 const trait_id trait = trait_;
173 const auto iter = my_mutations.find( trait );
174 if( iter == my_mutations.end() ) {
175 return;
176 }
177 my_mutations.erase( iter );
179 mutation_loss_effect( trait );
182}

References mutation_loss_effect(), my_mutations, rebuild_mutation_cache(), recalc_sight_limits(), and reset_encumbrance().

Referenced by clear_mutations(), wish_mutate_callback::key(), marloss_common(), mutate_towards(), iuse::mycus(), remove_mutation(), talk_effect_fun_t::set_remove_trait(), switch_mutations(), test_crossing_threshold(), toggle_trait(), and try_reject_mutagen().

◆ update_body() [1/2]

void Character::update_body ( )

Updates all "biology" by one turn.

Should be called once every turn.

Definition at line 4680 of file character.cpp.

4681{
4683}
void update_body()
Updates all "biology" by one turn.
Definition: character.cpp:4680

References calendar::turn, and update_body().

Referenced by game::do_turn(), npc::npc_update_body(), npc::on_load(), and update_body().

◆ update_body() [2/2]

void Character::update_body ( const time_point from,
const time_point to 
)

Updates all "biology" as if time between from and to passed.

Definition at line 4685 of file character.cpp.

4686{
4687 if( !is_npc() ) {
4688 update_stamina( to_turns<int>( to - from ) );
4689 }
4690 update_stomach( from, to );
4692 if( ticks_between( from, to, 3_minutes ) > 0 ) {
4693 magic->update_mana( *this->as_player(), to_turns<double>( 3_minutes ) );
4694 }
4695 const int five_mins = ticks_between( from, to, 5_minutes );
4696 if( five_mins > 0 ) {
4698 update_needs( five_mins );
4699 regen( five_mins );
4700 // Note: mend ticks once per 5 minutes, but wants rate in TURNS, not 5 minute intervals
4701 // TODO: change @ref med to take time_duration
4702 mend( five_mins * to_turns<int>( 5_minutes ) );
4703 }
4704 if( ticks_between( from, to, 24_hours ) > 0 ) {
4706 }
4707
4708 const int thirty_mins = ticks_between( from, to, 30_minutes );
4709 if( thirty_mins > 0 ) {
4710 // Radiation kills health even at low doses
4712 }
4713
4714 for( const auto &v : vitamin::all() ) {
4715 const time_duration rate = vitamin_rate( v.first );
4716 if( rate > 0_turns ) {
4717 int qty = ticks_between( from, to, rate );
4718 if( qty > 0 ) {
4719 vitamin_mod( v.first, 0 - qty );
4720 }
4721
4722 } else if( rate < 0_turns ) {
4723 // mutations can result in vitamins being generated (but never accumulated)
4724 int qty = ticks_between( from, to, -rate );
4725 if( qty > 0 ) {
4726 vitamin_mod( v.first, qty );
4727 }
4728 }
4729 }
4730
4731 do_skill_rust();
4732}
int ticks_between(const time_point &from, const time_point &to, const time_duration &tick_length)
Definition: character.cpp:4673
static const trait_id trait_RADIOGENIC("RADIOGENIC")
void check_needs_extremes()
Kills the player if too hungry, stimmed up etc., forces tired player to sleep and prints warnings.
Definition: character.cpp:4979
void do_skill_rust()
Definition: character.cpp:3535
void update_needs(int rate_multiplier)
Increases hunger, thirst, fatigue and stimulants wearing off.
Definition: character.cpp:4791
virtual void update_health(int external_modifiers=0)
Handles health fluctuations over time.
Definition: character.cpp:4636
void regen(int rate_multiplier)
Handles passive regeneration of pain and maybe hp.
Definition: character.cpp:4564
void update_stomach(const time_point &from, const time_point &to)
Updates the stomach to give accurate hunger messages.
Definition: character.cpp:4748
void mend(int rate_multiplier)
Handles the chance for broken limbs to spontaneously heal to 1 HP.
Definition: suffer.cpp:1603
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
void enforce_minimum_healing()
Definition: character.cpp:4626
void update_stamina(int turns)
Regenerates stamina.
Definition: character.cpp:7286

References vitamin::all(), Creature::as_player(), check_needs_extremes(), do_skill_rust(), enforce_minimum_healing(), get_rad(), has_trait(), Creature::is_npc(), magic, mend(), recalculate_enchantment_cache(), regen(), ticks_between(), trait_RADIOGENIC, update_health(), update_needs(), update_stamina(), update_stomach(), vitamin_mod(), and vitamin_rate().

◆ update_bodytemp()

void Character::update_bodytemp ( const map m,
const weather_manager weather 
)

Maintains body temperature.

Calculations that affect all body parts equally go here, not in the loop

Source : http://www.atc.army.mil/weather/windchill.pdf

Temperature and wind chill are main factors, mitigated by clothing warmth. Each 10 warmth protects against 2C of cold.

1200 turns in low risk, + 3 tics 450 turns in moderate risk, + 8 tics 50 turns in high risk, +72 tics

Let's say frostnip @ 1800 tics, frostbite @ 3600 tics

Chunked into 8 parts (http://imgur.com/xlTPmJF)

– 2 hour risk – Between 30F and 10F Between 10F and -5F, less than 20mph, -4x + 3y - 20 > 0, x : F, y : mph – 45 minute risk – Between 10F and -5F, less than 20mph, -4x + 3y - 20 < 0, x : F, y : mph Between 10F and -5F, greater than 20mph Less than -5F, less than 10 mph Less than -5F, more than 10 mph, -4x + 3y - 170 > 0, x : F, y : mph – 5 minute risk – Less than -5F, more than 10 mph, -4x + 3y - 170 < 0, x : F, y : mph Less than -35F, more than 10 mp

Definition at line 5198 of file character.cpp.

5199{
5200 if( has_trait( trait_DEBUG_NOTEMP ) ) {
5201 temp_cur.fill( BODYTEMP_NORM );
5202 temp_conv.fill( BODYTEMP_NORM );
5203 return;
5204 }
5205 /* Cache calls to g->get_temperature( player position ), used in several places in function */
5206 const auto player_local_temp = weather.get_temperature( pos() );
5207 // NOTE : visit weather.h for some details on the numbers used
5208 // In Celsius / 100
5209 int Ctemperature = static_cast<int>( 100 * units::fahrenheit_to_celsius( player_local_temp ) );
5210 const w_point &weather_point = get_weather().get_precise();
5211 int vehwindspeed = 0;
5212 const optional_vpart_position vp = m.veh_at( pos() );
5213 if( vp ) {
5214 vehwindspeed = std::abs( vp->vehicle().velocity / 100 ); // vehicle velocity in mph
5215 }
5216 const oter_id &cur_om_ter = overmap_buffer.ter( global_omt_location() );
5217 bool sheltered = weather::is_sheltered( m, pos() );
5218 double total_windpower = get_local_windpower( weather.windspeed + vehwindspeed, cur_om_ter,
5219 pos(),
5220 weather.winddirection, sheltered );
5221 int air_humidity = get_local_humidity( weather_point.humidity, weather.weather_id,
5222 sheltered );
5223 // Let's cache this not to check it num_bp times
5224 const bool has_bark = has_trait( trait_BARK );
5225 const bool has_heatsink = has_bionic( bio_heatsink ) || is_wearing( itype_rm13_armor_on ) ||
5227 const bool has_climate_control = in_climate_control();
5228 const bool use_floor_warmth = can_use_floor_warmth();
5229 const cata::optional<vpart_reference> boardable = vp.part_with_feature( "BOARDABLE", true );
5230 // In bodytemp units
5231 const int ambient_norm = 1900 - BODYTEMP_NORM;
5232
5233 /**
5234 * Calculations that affect all body parts equally go here, not in the loop
5235 */
5236 const int sunlight_warmth = weather::is_in_sunlight( m, pos(), weather.weather_id )
5237 ? ( weather.weather_id->sun_intensity == sun_intensity_type::high ? 1000 : 500 )
5238 : 0;
5239 const int best_fire = get_heat_radiation( pos(), true );
5240 const bool pyromania = has_trait( trait_PYROMANIA );
5241
5242 const int lying_warmth = use_floor_warmth ? floor_warmth( pos() ) : 0;
5243 const int water_temperature_raw =
5244 100 * units::fahrenheit_to_celsius( weather.get_water_temperature( pos() ) );
5245 // Rescale so that 0C is 0 (FREEZING) and 30C is 5k (NORM).
5246 const int water_temperature = water_temperature_raw * 5 / 3;
5247
5248 // Correction of body temperature due to traits and mutations
5249 // Lower heat is applied always
5250 const int mutation_heat_low = bodytemp_modifier_traits( true );
5251 const int mutation_heat_high = bodytemp_modifier_traits( false );
5252 // Difference between high and low is the "safe" heat - one we only apply if it's beneficial
5253 const int mutation_heat_bonus = mutation_heat_high - mutation_heat_low;
5254
5255 // Note: this is included in @ref weather::get_temperature(), so don't add to bodytemp!
5256 const int h_radiation = get_heat_radiation( pos(), false );
5257
5258 // If you're standing in water, air temperature is replaced by water temperature. No wind.
5259 const ter_id ter_at_pos = m.ter( pos() );
5260 const bool submerged = !in_vehicle && ter_at_pos->has_flag( TFLAG_DEEP_WATER );
5261 const bool submerged_low = !in_vehicle && ( submerged || ter_at_pos->has_flag( TFLAG_SWIMMABLE ) );
5262
5263 std::map<bodypart_id, std::vector<const item *>> clothing_map;
5264 std::map<bodypart_id, std::vector<const item *>> bonus_clothing_map;
5265 for( const bodypart_id &bp : get_all_body_parts() ) {
5266 clothing_map.emplace( bp, std::vector<const item *>() );
5267 bonus_clothing_map.emplace( bp, std::vector<const item *>() );
5268 // HACK: we're using temp_conv here to temporarily save
5269 // temperature values from before equalization.
5270 temp_conv[bp->token] = temp_cur[bp->token];
5271 }
5272
5273 // EQUALIZATION
5274 // We run it outside the loop because we can and so we should
5275 // Also, it makes bonus heat application more stable
5276 // TODO: Affect future convection temperature instead (might require adding back to loop)
5282
5285
5288
5289 for( const item &it : worn ) {
5290 // TODO: Port body part set id changes
5291 const body_part_set &covered = it.get_covered_body_parts();
5292 for( size_t i = 0; i < num_bp; i++ ) {
5293 body_part token = static_cast<body_part>( i );
5294 if( covered.test( token ) ) {
5295 clothing_map[convert_bp( token )].emplace_back( &it );
5296 }
5297 if( it.has_flag( flag_HOOD ) ) {
5298 bonus_clothing_map[body_part_head].emplace_back( &it );
5299 }
5300 if( it.has_flag( flag_COLLAR ) ) {
5301 bonus_clothing_map[body_part_mouth].emplace_back( &it );
5302 }
5303 if( it.has_flag( flag_POCKETS ) ) {
5304 bonus_clothing_map[body_part_hand_l].emplace_back( &it );
5305 bonus_clothing_map[body_part_hand_r].emplace_back( &it );
5306 }
5307 }
5308 }
5309 // If player is wielding something large, pockets are not usable
5310 if( weapon.volume() >= 500_ml ) {
5311 bonus_clothing_map[body_part_hand_l].clear();
5312 bonus_clothing_map[body_part_hand_r].clear();
5313 }
5314 // If player's head is encumbered, hood can't be put up
5315 if( encumb( body_part_head->token ) >= 10 ) {
5316 bonus_clothing_map[body_part_head].clear();
5317 }
5318 // Similar for mouth
5319 if( encumb( body_part_mouth->token ) >= 10 ) {
5320 bonus_clothing_map[body_part_mouth].clear();
5321 }
5322
5323 std::map<bodypart_id, int> warmth_per_bp = warmth::from_clothing( clothing_map );
5324 std::map<bodypart_id, int> bonus_warmth_per_bp = warmth::bonus_from_clothing( bonus_clothing_map );
5325 for( const auto &pr : warmth::from_effects( *this ) ) {
5326 warmth_per_bp[pr.first] += pr.second;
5327 }
5328
5329 std::map<bodypart_id, int> wind_res_per_bp = warmth::wind_resistance_from_clothing( clothing_map );
5330 std::map<bodypart_id, int> wind_res_per_bp_bonus = warmth::wind_resistance_from_clothing(
5331 bonus_clothing_map );
5332 for( std::pair<const bodypart_id, int> &bp_wind_res : wind_res_per_bp ) {
5333 int exposed = std::max( 0, 100 - bp_wind_res.second );
5334 int exposed_bonus = std::max( 0, 100 - wind_res_per_bp_bonus.at( bp_wind_res.first ) );
5335 int exposed_final = exposed * exposed_bonus / ( 100 * 100 );
5336 bp_wind_res.second = 100 - exposed_final;
5337 }
5339 for( std::pair<const bodypart_id, int> &bp_wind_res : wind_res_per_bp ) {
5340 bp_wind_res.second = 100;
5341 }
5342 }
5343 // We might not use this at all, so leave it empty
5344 // If we do need to use it, we'll initialize it (once) there
5345 std::map<bodypart_id, int> fire_armor_per_bp;
5346
5347 // Current temperature and converging temperature calculations
5348 for( const bodypart_id &bp : get_all_body_parts() ) {
5349 // Skip eyes
5350 if( bp == bodypart_id( "eyes" ) ) {
5351 continue;
5352 }
5353
5354 const bool submerged_bp = submerged ||
5355 ( submerged_low &&
5356 ( bp == body_part_foot_l ||
5357 bp == body_part_foot_r ||
5358 bp == body_part_leg_l ||
5359 bp == body_part_leg_r ) );
5360 // This adjusts the temperature scale to match the bodytemp scale
5361 const int adjusted_temp = submerged_bp ?
5362 water_temperature :
5363 ( Ctemperature - ambient_norm );
5364
5365 // Represents the fact that the body generates heat when it is cold.
5366 double scaled_temperature = logarithmic_range( BODYTEMP_VERY_COLD, BODYTEMP_VERY_HOT,
5367 temp_cur[bp->token] );
5368 // Produces a smooth curve between 30.0 and 60.0.
5369 double homeostasis_adjustment = 30.0 * ( 1.0 + scaled_temperature );
5370 int clothing_warmth_adjustment = static_cast<int>( homeostasis_adjustment * warmth_per_bp[bp] );
5371 int clothing_warmth_adjusted_bonus = static_cast<int>( homeostasis_adjustment *
5372 bonus_warmth_per_bp[bp] );
5373 // WINDCHILL
5374 double bp_windpower = total_windpower * ( 1 - wind_res_per_bp[bp] / 100.0 );
5375 // Calculate windchill
5376 int windchill = submerged_bp
5377 ? 0
5378 : get_local_windchill( player_local_temp,
5379 air_humidity,
5380 bp_windpower );
5381
5382 // Convergent temperature is affected by ambient temperature,
5383 // clothing warmth, and body wetness.
5384 int bp_conv = adjusted_temp
5385 + windchill * 100
5386 + clothing_warmth_adjustment
5387 + mutation_heat_low
5388 + sunlight_warmth;
5389
5390 // Bark : lowers blister count to -5; harder to get blisters
5391 // If the counter is high, your skin starts to burn
5392 int blister_count = ( has_bark ? -5 : 0 );
5393
5394 if( frostbite_timer[bp->token] > 0 ) {
5395 frostbite_timer[bp->token] -= std::min( 5, h_radiation );
5396 }
5397 blister_count += h_radiation - 111 > 0 ?
5398 std::max( static_cast<int>( std::sqrt( h_radiation - 111 ) ), 0 ) : 0;
5399
5400 if( has_heatsink ) {
5401 blister_count -= 20;
5402 }
5403 if( fire_armor_per_bp.empty() && blister_count > 0 ) {
5404 fire_armor_per_bp = get_armor_fire( clothing_map );
5405 }
5406 // BLISTERS : Skin gets blisters from intense heat exposure.
5407 // Fire protection protects from blisters.
5408 // Heatsinks give near-immunity.
5409 if( blister_count - fire_armor_per_bp[bp] > 0 ) {
5410 add_effect( effect_blisters, 1_turns, bp->token );
5411 if( pyromania ) {
5412 add_morale( MORALE_PYROMANIA_NEARFIRE, 10, 10, 1_hours,
5413 30_minutes ); // Proximity that's close enough to harm us gives us a bit of a thrill
5415 }
5416 } else if( pyromania && best_fire >= 1 ) { // Only give us fire bonus if there's actually fire
5417 add_morale( MORALE_PYROMANIA_NEARFIRE, 5, 5, 30_minutes,
5418 15_minutes ); // Gain a much smaller mood boost even if it doesn't hurt us
5420 }
5421
5422 // Climate Control eases the effects of high and low ambient temps
5423 if( has_climate_control ) {
5424 bp_conv = temp_corrected_by_climate_control( bp_conv );
5425 }
5426
5427 int bonus_fire_warmth = best_fire * 500;
5428
5429 const int comfortable_warmth = bonus_fire_warmth + lying_warmth;
5430 const int bonus_warmth = comfortable_warmth + mutation_heat_bonus + clothing_warmth_adjusted_bonus;
5431 if( bonus_warmth > 0 ) {
5432 // Approximate bp_conv needed to reach comfortable temperature in this very turn
5433 // Basically inverted formula for temp_cur below
5434 int desired = 501 * BODYTEMP_NORM - 499 * temp_cur[bp->token];
5435 if( std::abs( BODYTEMP_NORM - desired ) < 1000 ) {
5436 desired = BODYTEMP_NORM; // Ensure that it converges
5437 } else if( desired > BODYTEMP_HOT ) {
5438 desired = BODYTEMP_HOT; // Cap excess at sane temperature
5439 }
5440
5441 if( desired < bp_conv ) {
5442 // Too hot, can't help here
5443 } else if( desired < bp_conv + bonus_warmth ) {
5444 // Use some heat, but not all of it
5445 bp_conv = desired;
5446 } else {
5447 // Use all the heat
5448 bp_conv += bonus_warmth;
5449 }
5450
5451 // Morale bonus for comfiness - only if actually comfy (not too warm/cold)
5452 // Spread the morale bonus in time.
5453 if( comfortable_warmth > 0 &&
5454 // TODO: make this simpler and use time_duration/time_point
5455 to_turn<int>( calendar::turn ) % to_turns<int>( 1_minutes ) == to_turns<int>
5456 ( 1_minutes * bp->token ) / to_turns<int>( 1_minutes * num_bp ) &&
5458 get_effect_int( effect_hot, num_bp ) == 0 &&
5459 temp_cur[bp->token] > BODYTEMP_COLD && temp_cur[bp->token] <= BODYTEMP_NORM ) {
5460 add_morale( MORALE_COMFY, 1, 10, 2_minutes, 1_minutes, true );
5461 }
5462 }
5463
5464 // The current temperature model can't account for water temperature conduction well
5465 // Hack: cut non-water effects by 80% when in water
5466 if( submerged_bp ) {
5467 bp_conv = ( ( bp_conv - adjusted_temp ) / 5 ) + adjusted_temp;
5468 }
5469
5470 // FINAL CALCULATION : Increments current body temperature towards convergent.
5471 int temp_before = temp_cur[bp->token];
5472 int temp_difference = temp_before - bp_conv; // Negative if the player is warming up.
5473 int rounding_error = 0;
5474 // If temp_diff is small, the player cannot warm up due to rounding errors. This fixes that.
5475 if( temp_difference < 0 && temp_difference > -600 ) {
5476 rounding_error = 1;
5477 }
5478 // exp(-0.001) : half life of 60 minutes, exp(-0.002) : half life of 30 minutes,
5479 // exp(-0.003) : half life of 20 minutes, exp(-0.004) : half life of 15 minutes
5480 static const double change_mult_air = std::exp( -0.002 );
5481 static const double change_mult_water = std::exp( -0.008 );
5482 const double change_mult = submerged_bp ? change_mult_water : change_mult_air;
5483 if( temp_cur[bp->token] != bp_conv ) {
5484 temp_cur[bp->token] = static_cast<int>( temp_difference * change_mult )
5485 + bp_conv + rounding_error;
5486 }
5487 int temp_after = temp_cur[bp->token];
5488 // PENALTIES
5489 if( temp_cur[bp->token] < BODYTEMP_FREEZING ) {
5490 add_effect( effect_cold, 1_turns, bp->token, 3 );
5491 } else if( temp_cur[bp->token] < BODYTEMP_VERY_COLD ) {
5492 add_effect( effect_cold, 1_turns, bp->token, 2 );
5493 } else if( temp_cur[bp->token] < BODYTEMP_COLD ) {
5494 add_effect( effect_cold, 1_turns, bp->token, 1 );
5495 } else if( temp_cur[bp->token] > BODYTEMP_SCORCHING ) {
5496 add_effect( effect_hot, 1_turns, bp->token, 3 );
5497 if( bp->main_part.id() == bp ) {
5498 add_effect( effect_hot_speed, 1_turns, bp->token, 3 );
5499 }
5500 } else if( temp_cur[bp->token] > BODYTEMP_VERY_HOT ) {
5501 add_effect( effect_hot, 1_turns, bp->token, 2 );
5502 if( bp->main_part.id() == bp ) {
5503 add_effect( effect_hot_speed, 1_turns, bp->token, 2 );
5504 }
5505 } else if( temp_cur[bp->token] > BODYTEMP_HOT ) {
5506 add_effect( effect_hot, 1_turns, bp->token, 1 );
5507 if( bp->main_part.id() == bp ) {
5508 add_effect( effect_hot_speed, 1_turns, bp->token, 1 );
5509 }
5510 } else {
5511 if( temp_cur[bp->token] >= BODYTEMP_COLD ) {
5512 remove_effect( effect_cold, bp->token );
5513 }
5514 if( temp_cur[bp->token] <= BODYTEMP_HOT ) {
5515 remove_effect( effect_hot, bp->token );
5516 remove_effect( effect_hot_speed, bp->token );
5517 }
5518 }
5519
5520 // FROSTBITE - only occurs to hands, feet, face
5521 /**
5522
5523 Source : http://www.atc.army.mil/weather/windchill.pdf
5524
5525 Temperature and wind chill are main factors, mitigated by clothing warmth. Each 10 warmth protects against 2C of cold.
5526
5527 1200 turns in low risk, + 3 tics
5528 450 turns in moderate risk, + 8 tics
5529 50 turns in high risk, +72 tics
5530
5531 Let's say frostnip @ 1800 tics, frostbite @ 3600 tics
5532
5533 >> Chunked into 8 parts (http://imgur.com/xlTPmJF)
5534 -- 2 hour risk --
5535 Between 30F and 10F
5536 Between 10F and -5F, less than 20mph, -4x + 3y - 20 > 0, x : F, y : mph
5537 -- 45 minute risk --
5538 Between 10F and -5F, less than 20mph, -4x + 3y - 20 < 0, x : F, y : mph
5539 Between 10F and -5F, greater than 20mph
5540 Less than -5F, less than 10 mph
5541 Less than -5F, more than 10 mph, -4x + 3y - 170 > 0, x : F, y : mph
5542 -- 5 minute risk --
5543 Less than -5F, more than 10 mph, -4x + 3y - 170 < 0, x : F, y : mph
5544 Less than -35F, more than 10 mp
5545 **/
5546
5547 if( bp == body_part_mouth || bp == body_part_foot_r ||
5548 bp == body_part_foot_l || bp == body_part_hand_r || bp == body_part_hand_l ) {
5549 // Handle the frostbite timer
5550 // Need temps in F, windPower already in mph
5551 int wetness_percentage = 100 * body_wetness[bp->token] / drench_capacity[bp->token]; // 0 - 100
5552 // Warmth gives a slight buff to temperature resistance
5553 // Wetness gives a heavy nerf to temperature resistance
5554 double adjusted_warmth = warmth_per_bp.at( bp ) - wetness_percentage;
5555 int Ftemperature = static_cast<int>( player_local_temp + 0.2 * adjusted_warmth );
5556 // Windchill reduced by your armor
5557 int FBwindPower = static_cast<int>(
5558 total_windpower * ( 1 - wind_res_per_bp[ bp ] / 100.0 ) );
5559
5560 int intense = get_effect_int( effect_frostbite, bp->token );
5561
5562 // This has been broken down into 8 zones
5563 // Low risk zones (stops at frostnip)
5564 if( temp_cur[bp->token] < BODYTEMP_COLD &&
5565 ( ( Ftemperature < 30 && Ftemperature >= 10 ) ||
5566 ( Ftemperature < 10 && Ftemperature >= -5 &&
5567 FBwindPower < 20 && -4 * Ftemperature + 3 * FBwindPower - 20 >= 0 ) ) ) {
5568 if( frostbite_timer[bp->token] < 2000 ) {
5569 frostbite_timer[bp->token] += 3;
5570 }
5571 if( one_in( 100 ) && !has_effect( effect_frostbite, bp->token ) ) {
5572 add_msg( m_warning, _( "Your %s will be frostnipped in the next few hours." ),
5573 body_part_name( bp->token ) );
5574 }
5575 // Medium risk zones
5576 } else if( temp_cur[bp->token] < BODYTEMP_COLD &&
5577 ( ( Ftemperature < 10 && Ftemperature >= -5 && FBwindPower < 20 &&
5578 -4 * Ftemperature + 3 * FBwindPower - 20 < 0 ) ||
5579 ( Ftemperature < 10 && Ftemperature >= -5 && FBwindPower >= 20 ) ||
5580 ( Ftemperature < -5 && FBwindPower < 10 ) ||
5581 ( Ftemperature < -5 && FBwindPower >= 10 &&
5582 -4 * Ftemperature + 3 * FBwindPower - 170 >= 0 ) ) ) {
5583 frostbite_timer[bp->token] += 8;
5584 if( one_in( 100 ) && intense < 2 ) {
5585 add_msg( m_warning, _( "Your %s will be frostbitten within the hour!" ),
5586 body_part_name( bp->token ) );
5587 }
5588 // High risk zones
5589 } else if( temp_cur[bp->token] < BODYTEMP_COLD &&
5590 ( ( Ftemperature < -5 && FBwindPower >= 10 &&
5591 -4 * Ftemperature + 3 * FBwindPower - 170 < 0 ) ||
5592 ( Ftemperature < -35 && FBwindPower >= 10 ) ) ) {
5593 frostbite_timer[bp->token] += 72;
5594 if( one_in( 100 ) && intense < 2 ) {
5595 add_msg( m_warning, _( "Your %s will be frostbitten any minute now!" ),
5596 body_part_name( bp->token ) );
5597 }
5598 // Risk free, so reduce frostbite timer
5599 } else {
5600 frostbite_timer[bp->token] -= 3;
5601 }
5602
5603 // Handle the bestowing of frostbite
5604 if( frostbite_timer[bp->token] < 0 ) {
5605 frostbite_timer[bp->token] = 0;
5606 } else if( frostbite_timer[bp->token] > 4200 ) {
5607 // This ensures that the player will recover in at most 3 hours.
5608 frostbite_timer[bp->token] = 4200;
5609 }
5610 // Frostbite, no recovery possible
5611 if( frostbite_timer[bp->token] >= 3600 ) {
5612 add_effect( effect_frostbite, 1_turns, bp->token, 2 );
5614 // Else frostnip, add recovery if we were frostbitten
5615 } else if( frostbite_timer[bp->token] >= 1800 ) {
5616 if( intense == 2 ) {
5617 add_effect( effect_frostbite_recovery, 1_turns, bp->token );
5618 }
5619 add_effect( effect_frostbite, 1_turns, bp->token, 1 );
5620 // Else fully recovered
5621 } else if( frostbite_timer[bp->token] == 0 ) {
5622 remove_effect( effect_frostbite, bp->token );
5624 }
5625 }
5626 // Warn the player if condition worsens
5627 // HACK: we want overall temperature change, including equalization, and temp_conv
5628 // at this moment contains temperature values from before the equalization.
5629 temp_before = temp_conv[bp->token];
5630 if( temp_before > BODYTEMP_FREEZING && temp_after <= BODYTEMP_FREEZING ) {
5631 //~ %s is bodypart
5632 add_msg( m_warning, _( "You feel your %s beginning to go numb from the cold!" ),
5633 body_part_name( bp->token ) );
5634 } else if( temp_before > BODYTEMP_VERY_COLD && temp_after <= BODYTEMP_VERY_COLD ) {
5635 //~ %s is bodypart
5636 add_msg( m_warning, _( "You feel your %s getting very cold." ),
5637 body_part_name( bp->token ) );
5638 } else if( temp_before > BODYTEMP_COLD && temp_after <= BODYTEMP_COLD ) {
5639 //~ %s is bodypart
5640 add_msg( m_warning, _( "You feel your %s getting chilly." ),
5641 body_part_name( bp->token ) );
5642 } else if( temp_before < BODYTEMP_SCORCHING && temp_after >= BODYTEMP_SCORCHING ) {
5643 //~ %s is bodypart
5644 add_msg( m_bad, _( "You feel your %s getting red hot from the heat!" ),
5645 body_part_name( bp->token ) );
5646 } else if( temp_before < BODYTEMP_VERY_HOT && temp_after >= BODYTEMP_VERY_HOT ) {
5647 //~ %s is bodypart
5648 add_msg( m_warning, _( "You feel your %s getting very hot." ),
5649 body_part_name( bp->token ) );
5650 } else if( temp_before < BODYTEMP_HOT && temp_after >= BODYTEMP_HOT ) {
5651 //~ %s is bodypart
5652 add_msg( m_warning, _( "You feel your %s getting warm." ),
5653 body_part_name( bp->token ) );
5654 }
5655
5656 // Note: Numbers are based off of BODYTEMP at the top of weather.h
5657 // If torso is BODYTEMP_COLD which is 34C, the early stages of hypothermia begin
5658 // constant shivering will prevent the player from falling asleep.
5659 // Otherwise, if any other body part is BODYTEMP_VERY_COLD, or 31C
5660 // AND you have frostbite, then that also prevents you from sleeping
5661 if( in_sleep_state() ) {
5662 int curr_temperature = temp_cur[bp->token];
5663 if( bp == body_part_torso && curr_temperature <= BODYTEMP_COLD ) {
5664 add_msg( m_warning, _( "Your shivering prevents you from sleeping." ) );
5665 wake_up();
5666 } else if( bp != body_part_torso && curr_temperature <= BODYTEMP_VERY_COLD &&
5668 add_msg( m_warning, _( "You are too cold. Your frostbite prevents you from sleeping." ) );
5669 wake_up();
5670 }
5671 }
5672
5673 // Warn the player that wind is going to be a problem.
5674 // But only if it can be a problem, no need to spam player with "wind chills your scorching body"
5675 if( bp_conv <= BODYTEMP_COLD && windchill < -10 && one_in( 200 ) ) {
5676 add_msg( m_bad, _( "The wind is making your %s feel quite cold." ),
5677 body_part_name( bp->token ) );
5678 } else if( bp_conv <= BODYTEMP_COLD && windchill < -20 && one_in( 100 ) ) {
5679 add_msg( m_bad,
5680 _( "The wind is very strong, you should find some more wind-resistant clothing for your %s." ),
5681 body_part_name( bp->token ) );
5682 } else if( bp_conv <= BODYTEMP_COLD && windchill < -30 && one_in( 50 ) ) {
5683 add_msg( m_bad, _( "Your clothing is not providing enough protection from the wind for your %s!" ),
5684 body_part_name( bp->token ) );
5685 }
5686
5687 // Set temp_conv just once per bp for readability
5688 // TODO: Remove temp_conv, it's only really for display, so should not be in Character
5689 temp_conv[bp->token] = bp_conv;
5690 }
5691}
const bodypart_str_id body_part_foot_r("foot_r")
const bodypart_str_id body_part_hand_r("hand_r")
const bodypart_str_id body_part_leg_l("leg_l")
const bodypart_str_id body_part_arm_l("arm_l")
const bodypart_str_id body_part_torso("torso")
const bodypart_str_id body_part_arm_r("arm_r")
const bodypart_str_id body_part_leg_r("leg_r")
const bodypart_str_id body_part_mouth("mouth")
const bodypart_str_id body_part_head("head")
const bodypart_str_id body_part_hand_l("hand_l")
const bodypart_str_id body_part_foot_l("foot_l")
static const efftype_id effect_cold("cold")
static const trait_id trait_DEBUG_NOTEMP("DEBUG_NOTEMP")
static const trait_id trait_BARK("BARK")
static const flag_str_id flag_POCKETS("POCKETS")
static const efftype_id effect_hot("hot")
static const flag_str_id flag_HOOD("HOOD")
static const trait_id trait_PYROMANIA("PYROMANIA")
static const efftype_id effect_blisters("blisters")
static const efftype_id effect_frostbite_recovery("frostbite_recovery")
static const efftype_id effect_hot_speed("hot_speed")
static const flag_str_id flag_COLLAR("COLLAR")
static const efftype_id effect_frostbite("frostbite")
int temp_corrected_by_climate_control(int temperature) const
Value of the body temperature corrected by climate control.
Definition: character.cpp:9573
std::map< bodypart_id, int > get_armor_fire(const std::map< bodypart_id, std::vector< const item * > > &clothing_map) const
Returns overall fire resistance.
Definition: character.cpp:8400
bool can_use_floor_warmth() const
Can the player lie down and cover self with blankets etc.
Definition: character.cpp:9454
int bodytemp_modifier_traits(bool overheated) const
Correction factor of the body temperature due to traits and mutations.
Definition: character.cpp:9555
bool in_climate_control()
Returns true if the player is in a climate controlled area or armor.
Definition: character.cpp:3844
void temp_equalizer(const bodypart_id &bp1, const bodypart_id &bp2)
Equalizes heat between body parts.
Definition: character.cpp:5693
int floor_warmth(const tripoint &pos) const
Final warmth from the floor.
Definition: character.cpp:9540
int get_heat_radiation(const tripoint &location, bool direct)
Definition: game.cpp:1886
@ TFLAG_SWIMMABLE
Definition: mapdata.h:279
const morale_type MORALE_COMFY("morale_comfy")
constexpr double fahrenheit_to_celsius(double fahrenheit)
std::map< bodypart_id, int > bonus_from_clothing(const std::map< bodypart_id, std::vector< const item * > > &clothing_map)
Definition: character.cpp:9437
std::map< bodypart_id, int > wind_resistance_from_clothing(const std::map< bodypart_id, std::vector< const item * > > &clothing_map)
Returns wind resistance provided by armor, etc.
Definition: character.cpp:3900
std::map< bodypart_id, int > from_effects(const Character &c)
Definition: character.cpp:9443
std::map< bodypart_id, int > from_clothing(const std::map< bodypart_id, std::vector< const item * > > &clothing_map)
Definition: character.cpp:9431
bool is_in_sunlight(const map &m, const tripoint &p, const weather_type_id &weather)
Definition: weather.cpp:1162
bool is_sheltered(const map &m, const tripoint &p)
Definition: weather.cpp:1153
bool has_flag(const std::string &flag) const
Definition: mapdata.h:415

References _, Creature::add_effect(), add_morale(), add_msg(), bio_heatsink, body_part_arm_l, body_part_arm_r, body_part_foot_l, body_part_foot_r, body_part_hand_l, body_part_hand_r, body_part_head, body_part_leg_l, body_part_leg_r, body_part_mouth, body_part_name(), body_part_torso, body_wetness, BODYTEMP_COLD, BODYTEMP_FREEZING, BODYTEMP_HOT, bodytemp_modifier_traits(), BODYTEMP_NORM, BODYTEMP_SCORCHING, BODYTEMP_VERY_COLD, BODYTEMP_VERY_HOT, warmth::bonus_from_clothing(), can_use_floor_warmth(), convert_bp(), drench_capacity, effect_blisters, effect_cold, effect_frostbite, effect_frostbite_recovery, effect_hot, effect_hot_speed, encumb(), units::fahrenheit_to_celsius(), flag_COLLAR, flag_HOOD, flag_POCKETS, floor_warmth(), warmth::from_clothing(), warmth::from_effects(), frostbite_timer, Creature::get_all_body_parts(), get_armor_fire(), Creature::get_effect_int(), get_heat_radiation(), get_local_humidity(), get_local_windchill(), get_local_windpower(), weather_manager::get_precise(), get_weather(), global_omt_location(), has_active_mutation(), has_bionic(), Creature::has_effect(), map_data_common_t::has_flag(), has_trait(), high, w_point::humidity, in_climate_control(), in_sleep_state(), in_vehicle, weather::is_in_sunlight(), weather::is_sheltered(), is_wearing(), itype_rm13_armor_on, logarithmic_range(), m_bad, m_warning, MORALE_COMFY, MORALE_PYROMANIA_NEARFIRE, MORALE_PYROMANIA_NOFIRE, num_bp, one_in(), overmap_buffer, optional_vpart_position::part_with_feature(), pos(), rem_morale(), Creature::remove_effect(), temp_conv, temp_corrected_by_climate_control(), temp_cur, temp_equalizer(), map::ter(), overmapbuffer::ter(), body_part_set::test(), TFLAG_DEEP_WATER, TFLAG_SWIMMABLE, body_part_type::token, trait_BARK, trait_DEBUG_NOTEMP, trait_M_SKIN2, trait_M_SKIN3, trait_PYROMANIA, trait_SHELL2, calendar::turn, map::veh_at(), item::volume(), wake_up(), weapon, warmth::wind_resistance_from_clothing(), and worn.

Referenced by game::do_turn(), and iuse_transform::use().

◆ update_fuel_storage()

void Character::update_fuel_storage ( const itype_id fuel)

Updates which bionic contain fuel and which is empty.

Definition at line 2125 of file character.cpp.

2126{
2127 const item it( fuel );
2128 if( get_value( fuel.str() ).empty() ) {
2129 for( const bionic_id &bid : get_bionic_fueled_with( it ) ) {
2130 remove_value( bid.c_str() );
2131 }
2132 return;
2133 }
2134
2135 std::vector<bionic_id> bids = get_bionic_fueled_with( it );
2136 if( bids.empty() ) {
2137 return;
2138 }
2139 int amount_fuel_loaded = std::stoi( get_value( fuel.str() ) );
2140 std::vector<bionic_id> loaded_bio;
2141
2142 // Sort bionic in order of decreasing capacity
2143 // To fill the bigger ones firts.
2144 bool swap = true;
2145 while( swap ) {
2146 swap = false;
2147 for( size_t i = 0; i < bids.size() - 1; i++ ) {
2148 if( bids[i + 1]->fuel_capacity > bids[i]->fuel_capacity ) {
2149 std::swap( bids[i + 1], bids[i] );
2150 swap = true;
2151 }
2152 }
2153 }
2154
2155 for( const bionic_id &bid : bids ) {
2156 remove_value( bid.c_str() );
2157 if( bid->fuel_capacity <= amount_fuel_loaded ) {
2158 amount_fuel_loaded -= bid->fuel_capacity;
2159 loaded_bio.emplace_back( bid );
2160 } else if( amount_fuel_loaded != 0 ) {
2161 loaded_bio.emplace_back( bid );
2162 break;
2163 }
2164 }
2165
2166 for( const bionic_id &bd : loaded_bio ) {
2167 set_value( bd.str(), fuel.str() );
2168 }
2169
2170}
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496

References get_bionic_fueled_with(), Creature::get_value(), Creature::remove_value(), Creature::set_value(), string_id< T >::str(), and cata::swap().

Referenced by burn_fuel(), and fuel_bionic_with().

◆ update_health()

void Character::update_health ( int  external_modifiers = 0)
virtual

Handles health fluctuations over time.

Definition at line 4636 of file character.cpp.

4637{
4638 if( has_artifact_with( AEP_SICK ) ) {
4639 // Carrying a sickness artifact makes your health 50 points worse on average
4640 external_modifiers -= 50;
4641 }
4642 // Limit healthy_mod to [-200, 200].
4643 // This also sets approximate bounds for the character's health.
4644 if( get_healthy_mod() > get_max_healthy() ) {
4646 } else if( get_healthy_mod() < -200 ) {
4647 set_healthy_mod( -200 );
4648 }
4649
4650 // Active leukocyte breeder will keep your health near 100
4651 int effective_healthy_mod = get_healthy_mod();
4653 // Side effect: dependency
4654 mod_healthy_mod( -50, -200 );
4655 effective_healthy_mod = 100;
4656 }
4657
4658 // Health tends toward healthy_mod.
4659 // For small differences, it changes 4 points per day
4660 // For large ones, up to ~40% of the difference per day
4661 int health_change = effective_healthy_mod - get_healthy() + external_modifiers;
4662 mod_healthy( sgn( health_change ) * std::max( 1, std::abs( health_change ) / 10 ) );
4663
4664 // And healthy_mod decays over time.
4665 // Slowly near 0, but it's hard to overpower it near +/-100
4666 set_healthy_mod( std::round( get_healthy_mod() * 0.95f ) );
4667
4668 add_msg( m_debug, "Health: %d, Health mod: %d", get_healthy(), get_healthy_mod() );
4669}
static const bionic_id bio_leukocyte("bio_leukocyte")
int get_max_healthy() const
Definition: character.cpp:4559
@ AEP_SICK
Definition: enums.h:141

References add_msg(), AEP_SICK, bio_leukocyte, get_healthy(), get_healthy_mod(), get_max_healthy(), has_active_bionic(), has_artifact_with(), m_debug, mod_healthy(), mod_healthy_mod(), set_healthy_mod(), and sgn().

Referenced by update_body().

◆ update_morale()

void Character::update_morale ( )

Ticks down morale counters and removes them.

Definition at line 9014 of file character.cpp.

9015{
9016 morale->decay( 1_minutes );
9018}

References apply_persistent_morale(), and morale.

Referenced by game::do_turn().

◆ update_needs()

void Character::update_needs ( int  rate_multiplier)

Increases hunger, thirst, fatigue and stimulants wearing off.

rate_multiplier is for retroactive updates.

Definition at line 4791 of file character.cpp.

4792{
4793 const int current_stim = get_stim();
4794 // Hunger, thirst, & fatigue up every 5 minutes
4796 // No food/thirst/fatigue clock at all
4797 const bool debug_ls = has_trait( trait_DEBUG_LS );
4798 // No food/thirst, capped fatigue clock (only up to tired)
4799 const bool npc_no_food = is_npc() && get_option<bool>( "NO_NPC_FOOD" );
4800 const bool asleep = !sleep.is_null();
4801 const bool lying = asleep || has_effect( effect_lying_down ) ||
4803
4804 needs_rates rates = calc_needs_rates();
4805
4806 const bool wasnt_fatigued = get_fatigue() <= fatigue_levels::dead_tired;
4807 // Don't increase fatigue if sleeping or trying to sleep or if we're at the cap.
4808 if( get_fatigue() < 1050 && !asleep && !debug_ls ) {
4809 if( rates.fatigue > 0.0f ) {
4810 int fatigue_roll = roll_remainder( rates.fatigue * rate_multiplier );
4811 mod_fatigue( fatigue_roll );
4812
4813 // Synaptic regen bionic stops SD while awake and boosts it while sleeping
4815 // fatigue_roll should be around 1 - so the counter increases by 1 every minute on average,
4816 // but characters who need less sleep will also get less sleep deprived, and vice-versa.
4817
4818 // Note: Since needs are updated in 5-minute increments, we have to multiply the roll again by
4819 // 5. If rate_multiplier is > 1, fatigue_roll will be higher and this will work out.
4820 mod_sleep_deprivation( fatigue_roll * 5 );
4821 }
4822
4823 if( npc_no_food && get_fatigue() > fatigue_levels::tired ) {
4824 set_fatigue( static_cast<int>( fatigue_levels::tired ) );
4825 }
4826 if( npc_no_food ) {
4828 }
4829 }
4830 } else if( asleep && rates.recovery > 0.0f ) {
4831 int recovered = roll_remainder( rates.recovery * rate_multiplier );
4832 // Hibernation prevents waking up until you're hungry or thirsty
4833 if( get_fatigue() - recovered < -20 && !is_hibernating() ) {
4834 // Should be wake up, but that could prevent some retroactive regeneration
4835 sleep.set_duration( 1_turns );
4836 mod_fatigue( -25 );
4837 } else {
4839 recovered *= .5;
4840 }
4841 mod_fatigue( -recovered );
4842
4843 float rest_modifier = 1.0f;
4844 // Bionic doubles the base regen
4846 rest_modifier += 1.0f;
4847 }
4849 rest_modifier += 0.2f;
4850 }
4851
4852 const comfort_level comfort = base_comfort_value( pos() ).level;
4853
4854 // Best possible bed increases recovery by 30% of base
4855 if( comfort >= comfort_level::very_comfortable ) {
4856 rest_modifier += 0.3f;
4857 } else if( comfort >= comfort_level::comfortable ) {
4858 rest_modifier += 0.2f;
4859 } else if( comfort >= comfort_level::slightly_comfortable ) {
4860 rest_modifier += 0.1f;
4861 }
4862
4863 // 6 hours of sleep per day will let you avoid deprivation
4864 // 4 hours if on great bed plus melatonin
4865 // Math: 5 (fatigue to minutes), 3 (1:3 sleep to waking),
4866 // 2 (legacy sleep non-linearity thing)
4867 mod_sleep_deprivation( -rest_modifier * ( recovered * 3.0f * 5.0f / 2.0f ) );
4868
4869 }
4870 }
4871 if( is_player() && wasnt_fatigued && get_fatigue() > fatigue_levels::dead_tired && !lying ) {
4872 if( !activity ) {
4873 add_msg_if_player( m_warning, _( "You're feeling tired. %s to lie down for sleep." ),
4874 press_x( ACTION_SLEEP ) );
4875 } else {
4876 g->cancel_activity_query( _( "You're feeling tired." ) );
4877 }
4878 }
4879
4880 if( current_stim < 0 ) {
4881 set_stim( std::min( current_stim + rate_multiplier, 0 ) );
4882 } else if( current_stim > 0 ) {
4883 set_stim( std::max( current_stim - rate_multiplier, 0 ) );
4884 }
4885
4886 if( get_painkiller() > 0 ) {
4887 mod_painkiller( -std::min( get_painkiller(), rate_multiplier ) );
4888 }
4889
4890 // Huge folks take penalties for cramming themselves in vehicles
4891 if( in_vehicle && ( get_size() == MS_HUGE )
4893 vehicle *veh = veh_pointer_or_null( get_map().veh_at( pos() ) );
4894 // it's painful to work the controls, but passengers in open topped vehicles are fine
4895 if( veh && ( veh->enclosed_at( pos() ) || veh->player_in_control( *this->as_player() ) ) ) {
4897 _( "You're cramping up from stuffing yourself in this vehicle." ) );
4898 if( is_npc() ) {
4899 npc &as_npc = dynamic_cast<npc &>( *this );
4900 as_npc.complain_about( "cramped_vehicle", 1_hours, "<cramped_vehicle>", false );
4901 }
4902
4903 mod_pain( rng( 4, 6 ) );
4904 focus_pool -= 1;
4905 }
4906 }
4907}
std::string press_x(action_id act)
Definition: action.cpp:451
@ ACTION_SLEEP
Open sleep menu.
Definition: action.h:209
static const efftype_id effect_melatonin_supplements("melatonin")
static const trait_id trait_DEBUG_LS("DEBUG_LS")
static const bionic_id bio_synaptic_regen("bio_synaptic_regen")
static const efftype_id effect_lying_down("lying_down")
comfort_response_t base_comfort_value(const tripoint &p) const
Rate point's ability to serve as a bed.
Definition: character.cpp:5702
needs_rates calc_needs_rates() const
Definition: character.cpp:4908
virtual void mod_sleep_deprivation(int nsleep_deprivation)
Definition: character.cpp:4451
virtual npc * as_npc()
Definition: creature.h:110
bool complain_about(const std::string &issue, const time_duration &dur, const std::string &speech, bool force=false, sounds::sound_t priority=sounds::sound_t::speech)
Definition: npcmove.cpp:4448
bool enclosed_at(const tripoint &pos)
Definition: vehicle.cpp:6285

References _, ACT_TRY_SLEEP, ACTION_SLEEP, activity, Creature::add_msg_if_player(), Creature::as_npc(), base_comfort_value(), bio_synaptic_regen, calc_needs_rates(), comfortable, npc::complain_about(), dead_tired, effect_lying_down, effect_melatonin_supplements, effect_narcosis, effect_recently_coughed, effect_sleep, vehicle::enclosed_at(), needs_rates::fatigue, focus_pool, g, Creature::get_effect(), get_fatigue(), get_map(), get_painkiller(), get_size(), get_stim(), has_active_bionic(), Creature::has_effect(), has_trait(), player_activity::id(), in_vehicle, is_hibernating(), Creature::is_npc(), Creature::is_player(), Character::comfort_response_t::level, m_bad, m_warning, mod_fatigue(), Creature::mod_pain(), mod_painkiller(), mod_sleep_deprivation(), MS_HUGE, vehicle::player_in_control(), pos(), press_x(), needs_rates::recovery, rng(), roll_remainder(), set_fatigue(), set_sleep_deprivation(), set_stim(), sleep(), slightly_comfortable, tired, trait_DEBUG_LS, trait_NOPAIN, veh_pointer_or_null(), and very_comfortable.

Referenced by update_body().

◆ update_stamina()

void Character::update_stamina ( int  turns)

Regenerates stamina.

Definition at line 7286 of file character.cpp.

7287{
7288 static const std::string player_base_stamina_regen_rate( "PLAYER_BASE_STAMINA_REGEN_RATE" );
7289 static const std::string stamina_regen_modifier( "stamina_regen_modifier" );
7290 const float base_regen_rate = get_option<float>( player_base_stamina_regen_rate );
7291 const int current_stim = get_stim();
7292 float stamina_recovery = 0.0f;
7293 // Recover some stamina every turn.
7294 // max stamina modifers from mutation also affect stamina multi
7295 float stamina_multiplier = 1.0f + mutation_value( stamina_regen_modifier ) +
7296 ( mutation_value( "max_stamina_modifier" ) - 1.0f );
7297 // But mouth encumbrance interferes, even with mutated stamina.
7298 stamina_recovery += stamina_multiplier * std::max( 1.0f,
7299 base_regen_rate - ( encumb( bp_mouth ) / 5.0f ) );
7300 // TODO: recovering stamina causes hunger/thirst/fatigue.
7301 // TODO: Tiredness slowing recovery
7302
7303 // stim recovers stamina (or impairs recovery)
7304 if( current_stim > 0 ) {
7305 // TODO: Make stamina recovery with stims cost health
7306 stamina_recovery += std::min( 5.0f, current_stim / 15.0f );
7307 } else if( current_stim < 0 ) {
7308 // Affect it less near 0 and more near full
7309 // Negative stim kill at -200
7310 // At -100 stim it inflicts -20 malus to regen at 100% stamina,
7311 // effectivly countering stamina gain of default 20,
7312 // at 50% stamina its -10 (50%), cuts by 25% at 25% stamina
7313 stamina_recovery += current_stim / 5.0f * get_stamina() / get_stamina_max();
7314 }
7315
7316 const int max_stam = get_stamina_max();
7317 if( get_power_level() >= 3_kJ && has_active_bionic( bio_gills ) ) {
7318 int bonus = std::min<int>( units::to_kilojoule( get_power_level() ) / 3,
7319 max_stam - get_stamina() - stamina_recovery * turns );
7320 // so the effective recovery is up to 5x default
7321 bonus = std::min( bonus, 4 * static_cast<int>( base_regen_rate ) );
7322 if( bonus > 0 ) {
7323 stamina_recovery += bonus;
7324 bonus /= 10;
7325 bonus = std::max( bonus, 1 );
7327 }
7328 }
7329
7330 mod_stamina( roll_remainder( stamina_recovery * turns ) );
7331 add_msg( m_debug, "Stamina recovery: %d", roll_remainder( stamina_recovery * turns ) );
7332 // Cap at max
7333 set_stamina( std::min( std::max( get_stamina(), 0 ), max_stam ) );
7334}
static const bionic_id bio_gills("bio_gills")

References add_msg(), bio_gills, bp_mouth, encumb(), units::from_kilojoule(), get_power_level(), get_stamina(), get_stamina_max(), get_stim(), has_active_bionic(), m_debug, mod_power_level(), mod_stamina(), mutation_value(), roll_remainder(), set_stamina(), and units::to_kilojoule().

Referenced by update_body().

◆ update_stomach()

void Character::update_stomach ( const time_point from,
const time_point to 
)

Updates the stomach to give accurate hunger messages.

Definition at line 4748 of file character.cpp.

4749{
4750 const needs_rates rates = calc_needs_rates();
4751 // No food/thirst/fatigue clock at all
4752 const bool debug_ls = has_trait( trait_DEBUG_LS );
4753 // No food/thirst, capped fatigue clock (only up to tired)
4754 const bool npc_no_food = is_npc() && get_option<bool>( "NO_NPC_FOOD" );
4755 const bool foodless = debug_ls || npc_no_food;
4756 const bool mouse = has_trait( trait_NO_THIRST );
4757 const bool mycus = has_trait( trait_M_DEPENDENT );
4758 const float kcal_per_time = bmr() / ( 12.0f * 24.0f );
4759 const int five_mins = ticks_between( from, to, 5_minutes );
4760
4761 if( five_mins > 0 ) {
4762 // Digest nutrients in stomach
4763 food_summary digested_to_body = stomach.digest( rates, five_mins );
4764 // Apply nutrients, unless this is an NPC and NO_NPC_FOOD is enabled.
4765 if( !npc_no_food ) {
4766 mod_stored_kcal( digested_to_body.nutr.kcal );
4767 vitamins_mod( digested_to_body.nutr.vitamins, false );
4768 }
4769 if( !foodless && rates.hunger > 0.0f ) {
4770 // instead of hunger keeping track of how you're living, burn calories instead
4771 mod_stored_kcal( -roll_remainder( five_mins * kcal_per_time ) );
4772 }
4773 }
4774
4775 if( !foodless && rates.thirst > 0.0f ) {
4776 mod_thirst( roll_remainder( rates.thirst * five_mins ) );
4777 }
4778
4779 if( npc_no_food ) {
4780 set_thirst( static_cast<int>( thirst_levels::hydrated ) );
4782 }
4783
4784 // Mycus and Metabolic Rehydration makes thirst unnecessary
4785 // since water is not limited by intake but by absorption, we can just set thirst to zero
4786 if( mycus || mouse ) {
4787 set_thirst( 0 );
4788 }
4789}
static const trait_id trait_NO_THIRST("NO_THIRST")
static const trait_id trait_M_DEPENDENT("M_DEPENDENT")
void vitamins_mod(const std::map< vitamin_id, int > &, bool capped=true)
food_summary digest(const needs_rates &metabolic_rates, int five_mins)
Processes food and outputs nutrients that are finished processing Metabolic rates are required becaus...
Definition: stomach.cpp:132
int mycus(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:1438
nutrients nutr
Definition: stomach.h:53
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21

References bmr(), calc_needs_rates(), stomach_contents::digest(), has_trait(), needs_rates::hunger, hydrated, Creature::is_npc(), nutrients::kcal, max_stored_kcal(), mod_stored_kcal(), mod_thirst(), iuse::mycus(), food_summary::nutr, roll_remainder(), set_stored_kcal(), set_thirst(), stomach, needs_rates::thirst, ticks_between(), trait_DEBUG_LS, trait_M_DEPENDENT, trait_NO_THIRST, nutrients::vitamins, and vitamins_mod().

Referenced by update_body().

◆ update_type_of_scent() [1/2]

void Character::update_type_of_scent ( bool  init = false)

Definition at line 8740 of file character.cpp.

8741{
8742 scenttype_id new_scent = scenttype_id( "sc_human" );
8743 for( const trait_id &mut : get_mutations() ) {
8744 if( mut.obj().scent_typeid ) {
8745 new_scent = mut.obj().scent_typeid.value();
8746 }
8747 }
8748
8749 if( !init && new_scent != get_type_of_scent() ) {
8750 g->scent.reset();
8751 }
8752 set_type_of_scent( new_scent );
8753}
scenttype_id get_type_of_scent() const
Definition: character.cpp:8773

References g, get_mutations(), get_type_of_scent(), mutation_branch::scent_typeid, and set_type_of_scent().

Referenced by on_mutation_gain(), on_mutation_loss(), and update_type_of_scent().

◆ update_type_of_scent() [2/2]

void Character::update_type_of_scent ( const trait_id mut,
bool  gain = true 
)

Definition at line 8755 of file character.cpp.

8756{
8757 const cata::optional<scenttype_id> &mut_scent = mut->scent_typeid;
8758 if( mut_scent ) {
8759 if( gain && mut_scent.value() != get_type_of_scent() ) {
8760 set_type_of_scent( mut_scent.value() );
8761 g->scent.reset();
8762 } else {
8764 }
8765 }
8766}
cata::optional< scenttype_id > scent_typeid
What do you smell like.
Definition: mutation.h:157

References g, get_type_of_scent(), mutation_branch::scent_typeid, set_type_of_scent(), update_type_of_scent(), and cata::optional< T >::value().

◆ update_vitamins()

void Character::update_vitamins ( const vitamin_id vit)

Set vitamin deficiency/excess disease states dependent upon current vitamin levels.

Definition at line 8814 of file character.cpp.

8815{
8816 if( is_npc() ) {
8817 return; // NPCs cannot develop vitamin diseases
8818 }
8819
8820 efftype_id def = vit.obj().deficiency();
8821 efftype_id exc = vit.obj().excess();
8822
8823 int lvl = vit.obj().severity( vitamin_get( vit ) );
8824 if( lvl <= 0 ) {
8825 remove_effect( def );
8826 }
8827 if( lvl >= 0 ) {
8828 remove_effect( exc );
8829 }
8830 if( lvl > 0 ) {
8831 if( has_effect( def, num_bp ) ) {
8832 get_effect( def, num_bp ).set_intensity( lvl, true );
8833 } else {
8834 add_effect( def, 1_turns, num_bp, lvl );
8835 }
8836 }
8837 if( lvl < 0 ) {
8838 if( has_effect( exc, num_bp ) ) {
8839 get_effect( exc, num_bp ).set_intensity( -lvl, true );
8840 } else {
8841 add_effect( exc, 1_turns, num_bp, -lvl );
8842 }
8843 }
8844}
int vitamin_get(const vitamin_id &vit) const
Check current level of a vitamin.
int set_intensity(int val, bool alert=false)
Sets intensity of effect capped by range [1..max_intensity].
Definition: effect.cpp:858
const efftype_id & deficiency() const
Disease effect with increasing intensity proportional to vitamin deficiency.
Definition: vitamin.h:57
const efftype_id & excess() const
Disease effect with increasing intensity proportional to vitamin excess.
Definition: vitamin.h:62
int severity(int qty) const
Get intensity of deficiency or zero if not deficient for specified qty.
Definition: vitamin.cpp:39

References Creature::add_effect(), vitamin::deficiency(), vitamin::excess(), Creature::get_effect(), Creature::has_effect(), Creature::is_npc(), num_bp, string_id< T >::obj(), Creature::remove_effect(), effect::set_intensity(), vitamin::severity(), and vitamin_get().

Referenced by vitamin_mod().

◆ use_amount()

std::list< item > Character::use_amount ( itype_id  it,
int  quantity,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Definition at line 9640 of file character.cpp.

9642{
9643 std::list<item> ret;
9644 if( weapon.use_amount( it, quantity, ret ) ) {
9645 remove_weapon();
9646 }
9647 for( auto a = worn.begin(); a != worn.end() && quantity > 0; ) {
9648 if( a->use_amount( it, quantity, ret, filter ) ) {
9649 a->on_takeoff( *this );
9650 a = worn.erase( a );
9651 } else {
9652 ++a;
9653 }
9654 }
9655 if( quantity <= 0 ) {
9656 return ret;
9657 }
9658 std::list<item> tmp = inv.use_amount( it, quantity, filter );
9659 ret.splice( ret.end(), tmp );
9660 return ret;
9661}
std::list< item > use_amount(itype_id it, int quantity, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: inventory.cpp:852
bool use_amount(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Consume a specific amount of items of a specific type.
Definition: item.cpp:8328
constexpr double a
Definition: magic.cpp:1030

References a, inv, remove_weapon(), cata::hash64_detail::ret, item::use_amount(), inventory::use_amount(), weapon, and worn.

Referenced by computer_session::action_srcf_elevator(), iexamine::cardreader(), iexamine::cardreader_robofac(), player::consume_items(), game::find_or_make_stairs(), hack_attempt(), iexamine::pedestal_temple(), activity_handlers::plant_seed_finish(), vehicle::reload_seeds(), talk_effect_fun_t::set_consume_item(), talk_effect_fun_t::set_u_sell_item(), sinkhole_safety_roll(), and npc_trading::transfer_items().

◆ use_charges()

std::list< item > Character::use_charges ( const itype_id what,
int  qty,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Definition at line 9672 of file character.cpp.

9674{
9675 std::list<item> res;
9676
9677 if( qty <= 0 ) {
9678 return res;
9679
9680 } else if( what == itype_toolset ) {
9682 return res;
9683
9684 } else if( what == itype_fire ) {
9685 use_fire( qty );
9686 return res;
9687
9688 } else if( what == itype_bio_armor ) {
9689 float mod_qty = 0;
9690 float efficiency = 1;
9691 for( const bionic &bio : *my_bionics ) {
9692 if( bio.powered && bio.info().has_flag( flag_BIONIC_ARMOR_INTERFACE ) ) {
9693 efficiency = std::max( efficiency, bio.info().fuel_efficiency );
9694 }
9695 }
9696 if( efficiency == 1 ) {
9697 debugmsg( "Player lacks a bionic armor interface with fuel efficiency field." );
9698 }
9699 mod_qty = qty / efficiency;
9701 return res;
9702
9703 } else if( what == itype_UPS ) {
9704 if( is_mounted() && mounted_creature.get()->has_flag( MF_RIDEABLE_MECH ) &&
9705 mounted_creature.get()->battery_item ) {
9706 auto mons = mounted_creature.get();
9707 int power_drain = std::min( mons->battery_item->ammo_remaining(), qty );
9708 mons->use_mech_power( -power_drain );
9709 qty -= std::min( qty, power_drain );
9710 return res;
9711 }
9712 if( has_power() && has_active_bionic( bio_ups ) ) {
9713 int bio = std::min( units::to_kilojoule( get_power_level() ), qty );
9715 qty -= std::min( qty, bio );
9716 }
9717
9718 int adv = charges_of( itype_adv_UPS_off, static_cast<int>( std::ceil( qty * 0.6 ) ) );
9719 if( adv > 0 ) {
9720 std::list<item> found = use_charges( itype_adv_UPS_off, adv );
9721 res.splice( res.end(), found );
9722 qty -= std::min( qty, static_cast<int>( adv / 0.6 ) );
9723 }
9724
9725 int ups = charges_of( itype_UPS_off, qty );
9726 if( ups > 0 ) {
9727 std::list<item> found = use_charges( itype_UPS_off, ups );
9728 res.splice( res.end(), found );
9729 qty -= std::min( qty, ups );
9730 }
9731 return res;
9732
9733 }
9734
9735 std::vector<item *> del;
9736
9737 bool has_tool_with_UPS = false;
9738 visit_items( [this, &what, &qty, &res, &del, &has_tool_with_UPS, &filter]( item * e ) {
9739 if( e->use_charges( what, qty, res, pos(), filter ) ) {
9740 del.push_back( e );
9741 }
9742 if( filter( *e ) && e->typeId() == what && e->has_flag( flag_USE_UPS ) ) {
9743 has_tool_with_UPS = true;
9744 }
9745 return qty > 0 ? VisitResponse::SKIP : VisitResponse::ABORT;
9746 } );
9747
9748 for( auto e : del ) {
9749 remove_item( *e );
9750 }
9751
9752 if( has_tool_with_UPS ) {
9753 use_charges( itype_UPS, qty );
9754 }
9755
9756 return res;
9757}
static const itype_id itype_toolset("toolset")
static const itype_id itype_adv_UPS_off("adv_UPS_off")
static const bionic_id bio_ups("bio_ups")
static const itype_id itype_UPS_off("UPS_off")
void use_fire(int quantity)
Definition: character.cpp:9823
bool use_charges(const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
Consumes specified charges (or fewer) from this and any contained items.
Definition: item.cpp:8448

References ABORT, bio_ups, visitable< Character >::charges_of(), debugmsg, flag_BIONIC_ARMOR_INTERFACE, flag_USE_UPS(), units::from_kilojoule(), get_power_level(), has_active_bionic(), item::has_flag(), has_power(), is_mounted(), itype_adv_UPS_off, itype_bio_armor, itype_fire, itype_toolset, itype_UPS, itype_UPS_off, MF_RIDEABLE_MECH, mod_power_level(), mounted_creature, my_bionics, pos(), visitable< Character >::remove_item(), SKIP, units::to_kilojoule(), item::typeId(), item::use_charges(), use_charges(), use_fire(), and visitable< Character >::visit_items().

Referenced by iexamine::arcfurnace_empty(), consume_charges(), player::consume_items(), player::consume_med(), consume_remote_fuel(), player::consume_tools(), player::eat(), iuse::ecig(), iexamine::fertilize_plant(), player::fire_gun(), iexamine::fireplace(), iexamine::fvat_empty(), activity_handlers::gunmod_add_finish(), hack_attempt(), iexamine::keg(), iexamine::kiln_empty(), iexamine::pay_gas(), activity_handlers::plant_seed_finish(), player::process_items(), iexamine::reload_furniture(), vehicle::reload_seeds(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), talk_effect_fun_t::set_u_sell_item(), smoker_activate(), npc_trading::transfer_items(), try_consume(), try_start_hacking(), consume_drug_iuse::use(), place_monster_iuse::use(), cauterize_actor::use(), use_charges(), use_charges_if_avail(), use_fire(), and iexamine::vending().

◆ use_charges_if_avail()

bool Character::use_charges_if_avail ( const itype_id it,
int  quantity 
)

Definition at line 9663 of file character.cpp.

9664{
9665 if( has_charges( it, quantity ) ) {
9666 use_charges( it, quantity );
9667 return true;
9668 }
9669 return false;
9670}

References has_charges(), and use_charges().

Referenced by iuse::arrow_flammable(), iuse::firecracker(), activity_handlers::game_do_turn(), iuse::meth(), iuse::note_bionics(), item::process_tool(), item::reload(), iuse::smoking(), suffer_from_asthma(), and iuse_transform::use().

◆ use_fire()

void Character::use_fire ( int  quantity)

Definition at line 9823 of file character.cpp.

9824{
9825 //Okay, so checks for nearby fires first,
9826 //then held lit torch or candle, bionic tool/lighter/laser
9827 //tries to use 1 charge of lighters, matches, flame throwers
9828 //If there is enough power, will use power of one activation of the bio_lighter, bio_tools and bio_laser
9829 // (home made, military), hotplate, welder in that order.
9830 // bio_lighter, bio_laser, bio_tools, has_active_bionic("bio_tools"
9831
9832 if( get_map().has_nearby_fire( pos() ) ) {
9833 return;
9834 } else if( has_item_with_flag( "FIRE" ) ) {
9835 return;
9836 } else if( has_item_with_flag( "FIRESTARTER" ) ) {
9837 auto firestarters = all_items_with_flag( "FIRESTARTER" );
9838 for( auto &i : firestarters ) {
9839 if( has_charges( i->typeId(), quantity ) ) {
9840 use_charges( i->typeId(), quantity );
9841 return;
9842 }
9843 }
9844 } else if( has_active_bionic( bio_tools ) && get_power_level() > quantity * 5_kJ ) {
9845 mod_power_level( -quantity * 5_kJ );
9846 return;
9847 } else if( has_bionic( bio_lighter ) && get_power_level() > quantity * 5_kJ ) {
9848 mod_power_level( -quantity * 5_kJ );
9849 return;
9850 } else if( has_bionic( bio_laser ) && get_power_level() > quantity * 5_kJ ) {
9851 mod_power_level( -quantity * 5_kJ );
9852 return;
9853 }
9854}

References all_items_with_flag(), bio_laser, bio_lighter, bio_tools, get_map(), get_power_level(), has_active_bionic(), has_bionic(), has_charges(), has_item_with_flag(), mod_power_level(), pos(), and use_charges().

Referenced by use_charges().

◆ used_weapon() [1/2]

item & Character::used_weapon ( )

Definition at line 140 of file melee.cpp.

141{
142 return const_cast<item &>( const_cast<const Character *>( this )->used_weapon() );
143}

References used_weapon().

◆ used_weapon() [2/2]

const item & Character::used_weapon ( ) const

Returns a reference to the item which will be used to make attacks.

At the moment it's always weapon or a reference to a null item.

Definition at line 135 of file melee.cpp.

136{
137 return martial_arts_data->selected_force_unarmed() ? null_item_reference() : weapon;
138}

References martial_arts_data, null_item_reference(), and weapon.

Referenced by get_melee_hit_base(), ma_requirements::is_valid_character(), melee_attack(), player::on_dodge(), unarmed_attack(), and used_weapon().

◆ valid_aoe_technique() [1/2]

bool Character::valid_aoe_technique ( Creature t,
const ma_technique technique 
)
private

Check if an area-of-effect technique has valid targets.

Definition at line 1217 of file melee.cpp.

1218{
1219 std::vector<Creature *> dummy_targets;
1220 return valid_aoe_technique( t, technique, dummy_targets );
1221}

References valid_aoe_technique().

Referenced by perform_technique(), pick_technique(), and valid_aoe_technique().

◆ valid_aoe_technique() [2/2]

bool Character::valid_aoe_technique ( Creature t,
const ma_technique technique,
std::vector< Creature * > &  targets 
)
private

Definition at line 1223 of file melee.cpp.

1225{
1226 if( technique.aoe.empty() ) {
1227 return false;
1228 }
1229
1230 // pre-computed matrix of adjacent squares
1231 std::array<int, 9> offset_a = {{0, -1, -1, 1, 0, -1, 1, 1, 0 }};
1232 std::array<int, 9> offset_b = {{-1, -1, 0, -1, 0, 1, 0, 1, 1 }};
1233
1234 // filter the values to be between -1 and 1 to avoid indexing the array out of bounds
1235 int dy = std::max( -1, std::min( 1, t.posy() - posy() ) );
1236 int dx = std::max( -1, std::min( 1, t.posx() - posx() ) );
1237 int lookup = dy + 1 + 3 * ( dx + 1 );
1238
1239 //wide hits all targets adjacent to the attacker and the target
1240 if( technique.aoe == "wide" ) {
1241 //check if either (or both) of the squares next to our target contain a possible victim
1242 //offsets are a pre-computed matrix allowing us to quickly lookup adjacent squares
1243 tripoint left = pos() + tripoint( offset_a[lookup], offset_b[lookup], 0 );
1244 tripoint right = pos() + tripoint( offset_b[lookup], -offset_a[lookup], 0 );
1245
1246 monster *const mon_l = g->critter_at<monster>( left );
1247 if( mon_l && mon_l->friendly == 0 ) {
1248 targets.push_back( mon_l );
1249 }
1250 monster *const mon_r = g->critter_at<monster>( right );
1251 if( mon_r && mon_r->friendly == 0 ) {
1252 targets.push_back( mon_r );
1253 }
1254
1255 npc *const npc_l = g->critter_at<npc>( left );
1256 npc *const npc_r = g->critter_at<npc>( right );
1257 if( npc_l && npc_l->is_enemy() ) {
1258 targets.push_back( npc_l );
1259 }
1260 if( npc_r && npc_r->is_enemy() ) {
1261 targets.push_back( npc_r );
1262 }
1263 if( !targets.empty() ) {
1264 return true;
1265 }
1266 }
1267
1268 if( technique.aoe == "impale" ) {
1269 // Impale hits the target and a single target behind them
1270 // Check if the square cardinally behind our target, or to the left / right,
1271 // contains a possible target.
1272 tripoint left = t.pos() + tripoint( offset_a[lookup], offset_b[lookup], 0 );
1273 tripoint target_pos = t.pos() + ( t.pos() - pos() );
1274 tripoint right = t.pos() + tripoint( offset_b[lookup], -offset_b[lookup], 0 );
1275
1276 monster *const mon_l = g->critter_at<monster>( left );
1277 monster *const mon_t = g->critter_at<monster>( target_pos );
1278 monster *const mon_r = g->critter_at<monster>( right );
1279 if( mon_l && mon_l->friendly == 0 ) {
1280 targets.push_back( mon_l );
1281 }
1282 if( mon_t && mon_t->friendly == 0 ) {
1283 targets.push_back( mon_t );
1284 }
1285 if( mon_r && mon_r->friendly == 0 ) {
1286 targets.push_back( mon_r );
1287 }
1288
1289 npc *const npc_l = g->critter_at<npc>( left );
1290 npc *const npc_t = g->critter_at<npc>( target_pos );
1291 npc *const npc_r = g->critter_at<npc>( right );
1292 if( npc_l && npc_l->is_enemy() ) {
1293 targets.push_back( npc_l );
1294 }
1295 if( npc_t && npc_t->is_enemy() ) {
1296 targets.push_back( npc_t );
1297 }
1298 if( npc_r && npc_r->is_enemy() ) {
1299 targets.push_back( npc_r );
1300 }
1301 if( !targets.empty() ) {
1302 return true;
1303 }
1304 }
1305
1306 if( targets.empty() && technique.aoe == "spin" ) {
1307 for( const tripoint &tmp : g->m.points_in_radius( pos(), 1 ) ) {
1308 if( tmp == t.pos() ) {
1309 continue;
1310 }
1311 monster *const mon = g->critter_at<monster>( tmp );
1312 if( mon && mon->friendly == 0 ) {
1313 targets.push_back( mon );
1314 }
1315 npc *const np = g->critter_at<npc>( tmp );
1316 if( np && np->is_enemy() ) {
1317 targets.push_back( np );
1318 }
1319 }
1320 //don't trigger circle for fewer than 2 targets
1321 if( targets.size() < 2 ) {
1322 targets.clear();
1323 } else {
1324 return true;
1325 }
1326 }
1327 return false;
1328}
bool is_enemy() const
Definition: npc.cpp:2040

References ma_technique::aoe, monster::friendly, g, npc::is_enemy(), left, Creature::pos(), pos(), Creature::posx(), posx(), Creature::posy(), posy(), and right.

◆ visibility()

int Character::visibility ( bool  check_color = false,
int  stillness = 0 
) const

Checks is_invisible() as well as other factors.

Definition at line 6374 of file character.cpp.

6375{
6376 // 0-100 %
6377 if( is_invisible() ) {
6378 return 0;
6379 }
6380 // TODO:
6381 // if ( dark_clothing() && light check ...
6382 int stealth_modifier = std::floor( mutation_value( "stealth_modifier" ) );
6383 return clamp( 100 - stealth_modifier, 40, 160 );
6384}
bool is_invisible() const
Definition: character.cpp:6364

References clamp(), is_invisible(), and mutation_value().

◆ visible_mutations()

std::string Character::visible_mutations ( int  visibility_cap) const

Returns an enumeration of visible mutations with colors.

Definition at line 1753 of file mutation.cpp.

1754{
1755 const std::vector<trait_id> &my_muts = get_mutations();
1756 const std::string trait_str = enumerate_as_string( my_muts.begin(), my_muts.end(),
1757 [visibility_cap ]( const trait_id & pr ) -> std::string {
1758 const auto &mut_branch = pr.obj();
1759 // Finally some use for visibility trait of mutations
1760 if( mut_branch.visibility > 0 && mut_branch.visibility >= visibility_cap )
1761 {
1762 return colorize( mut_branch.name(), mut_branch.get_display_color() );
1763 }
1764
1765 return std::string();
1766 } );
1767 return trait_str;
1768}

References enumerate_as_string(), and get_mutations().

Referenced by npc::print_info(), and short_description_parts().

◆ vitamin_get()

int Character::vitamin_get ( const vitamin_id vit) const

Check current level of a vitamin.

Accesses level of a given vitamin. If the vitamin_id specified does not exist then this function simply returns 0.

Parameters
vitID of vitamin to check level for.
Returns
current level for specified vitamin

Definition at line 576 of file consumption.cpp.

577{
578 if( get_option<bool>( "NO_VITAMINS" ) && vit->type() == vitamin_type::VITAMIN ) {
579 return 0;
580 }
581
582 const auto &v = vitamin_levels.find( vit );
583 return v != vitamin_levels.end() ? v->second : 0;
584}
const vitamin_type & type() const
Definition: vitamin.h:40
@ VITAMIN
Definition: vitamin.h:19

References vitamin::type(), VITAMIN, and vitamin_levels.

Referenced by debug_menu::character_edit_menu(), eff_fun_mutating(), and update_vitamins().

◆ vitamin_mod()

int Character::vitamin_mod ( const vitamin_id vit,
int  qty,
bool  capped = true 
)

Add or subtract vitamins from character storage pools.

Parameters
vitID of vitamin to modify
qtyamount by which to adjust vitamin (negative values are permitted)
cappedif true prevent vitamins which can accumulate in excess from doing so
Returns
adjusted level for the vitamin or zero if vitamin does not exist

Definition at line 544 of file consumption.cpp.

545{
546 if( !vit.is_valid() ) {
547 debugmsg( "Vitamin with id %s does not exist, and cannot be modified", vit.str() );
548 return 0;
549 }
550 // What's going on here? Emplace returns either an iterator to the inserted
551 // item or, if it already exists, an iterator to the (unchanged) extant item
552 // (Okay, technically it returns a pair<iterator, bool>, the iterator is what we want)
553 auto it = vitamin_levels.emplace( vit, 0 ).first;
554 const vitamin &v = *it->first;
555
556 if( qty > 0 ) {
557 // Accumulations can never occur from food sources
558 it->second = std::min( it->second + qty, capped ? 0 : v.max() );
559 update_vitamins( vit );
560
561 } else if( qty < 0 ) {
562 it->second = std::max( it->second + qty, v.min() );
563 update_vitamins( vit );
564 }
565
566 return it->second;
567}
void update_vitamins(const vitamin_id &vit)
Set vitamin deficiency/excess disease states dependent upon current vitamin levels.
Definition: character.cpp:8814
int max() const
Upper bound for any accumulation of this vitamin.
Definition: vitamin.h:72
int min() const
Lower bound for deficiency of this vitamin.
Definition: vitamin.h:67

References debugmsg, string_id< T >::is_valid(), vitamin::max(), vitamin::min(), string_id< T >::str(), update_vitamins(), and vitamin_levels.

Referenced by eff_fun_bleed(), rooted(), suffer_from_other_mutations(), suffer_in_sunlight(), update_body(), consume_drug_iuse::use(), vitamin_set(), and vitamins_mod().

◆ vitamin_rate()

time_duration Character::vitamin_rate ( const vitamin_id vit) const

Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.

Definition at line 529 of file consumption.cpp.

530{
531 time_duration res = vit.obj().rate();
532
533 for( const auto &m : get_mutations() ) {
534 const auto &mut = m.obj();
535 auto iter = mut.vitamin_rates.find( vit );
536 if( iter != mut.vitamin_rates.end() ) {
537 res += iter->second;
538 }
539 }
540
541 return res;
542}
time_duration rate() const
Usage rate of vitamin (time to consume unit) Lower bound is zero whereby vitamin is not required (but...
Definition: vitamin.h:80

References get_mutations(), string_id< T >::obj(), and vitamin::rate().

Referenced by update_body(), and consume_drug_iuse::use().

◆ vitamin_set()

bool Character::vitamin_set ( const vitamin_id vit,
int  qty 
)

Sets level of a vitamin or returns false if id given in vit does not exist.

Note
status effects are still set for deficiency/excess
Parameters
[in]vitID of vitamin to adjust quantity for
[in]qtyQuantity to set level to
Returns
false if given vitamin_id does not exist, otherwise true

Definition at line 586 of file consumption.cpp.

587{
588 auto v = vitamin_levels.find( vit );
589 if( v == vitamin_levels.end() ) {
590 return false;
591 }
592 vitamin_mod( vit, qty - v->second, false );
593
594 return true;
595}

References vitamin_levels, and vitamin_mod().

Referenced by debug_menu::character_edit_menu(), eff_fun_mutating(), and eff_fun_toxin_buildup().

◆ vitamins_mod()

void Character::vitamins_mod ( const std::map< vitamin_id, int > &  vitamins,
bool  capped = true 
)

Definition at line 569 of file consumption.cpp.

570{
571 for( auto vit : vitamins ) {
572 vitamin_mod( vit.first, vit.second, capped );
573 }
574}

References vitamin_mod().

Referenced by update_stomach().

◆ volume_capacity()

◆ volume_capacity_reduced_by()

units::volume Character::volume_capacity_reduced_by ( const units::volume mod,
const excluded_stacks without = {} 
) const

Definition at line 2859 of file character.cpp.

2861{
2863 return units::volume_max;
2864 }
2865
2867 for( const auto &i : worn ) {
2868 if( !without.count( &i ) ) {
2869 ret += i.get_storage();
2870 }
2871 }
2872 if( has_bionic( bio_storage ) ) {
2873 ret += 2_liter;
2874 }
2875 if( has_trait( trait_SHELL ) ) {
2876 ret += 4_liter;
2877 }
2879 ret += 6_liter;
2880 }
2881 if( has_trait( trait_PACKMULE ) ) {
2882 ret = ret * 1.4;
2883 }
2884 if( has_trait( trait_DISORGANIZED ) ) {
2885 ret = ret * 0.6;
2886 }
2887 return std::max( ret, 0_ml );
2888}
static const trait_id trait_SHELL("SHELL")
static const trait_id trait_DISORGANIZED("DISORGANIZED")
static const trait_id trait_PACKMULE("PACKMULE")
static const bionic_id bio_storage("bio_storage")
const volume volume_max
Definition: units_volume.h:21

References bio_storage, has_active_mutation(), has_bionic(), has_trait(), cata::hash64_detail::ret, trait_DEBUG_STORAGE, trait_DISORGANIZED, trait_PACKMULE, trait_SHELL, trait_SHELL2, units::volume_max, and worn.

Referenced by inventory_drop_selector::get_raw_stats(), pickup::reorder_for_dropping(), player::takeoff(), and volume_capacity().

◆ volume_carried()

◆ volume_carried_reduced_by()

units::volume Character::volume_carried_reduced_by ( const excluded_stacks without) const

Definition at line 2801 of file character.cpp.

2802{
2803 if( without.empty() ) {
2804 return inv.volume();
2805 } else {
2806 return inv.volume_without( without );
2807 }
2808}
units::volume volume_without(const excluded_stacks &without) const
Definition: inventory.cpp:1068

References inv, inventory::volume(), and inventory::volume_without().

Referenced by inventory_drop_selector::get_raw_stats().

◆ vomit()

void Character::vomit ( )

Handles Character vomiting effects.

Definition at line 7808 of file character.cpp.

7809{
7810 g->events().send<event_type::throws_up>( getID() );
7811
7812 map &here = get_map();
7813 if( get_effect_int( effect_fungus ) >= 3 ) {
7814 add_msg_player_or_npc( m_bad, _( "You vomit thousands of live spores!" ),
7815 _( "<npcname> vomits thousands of live spores!" ) );
7816 fungal_effects( *g, here ).fungalize( pos(), this );
7817 } else if( stomach.get_calories() > 0 || get_thirst() < 0 ) {
7818 add_msg_player_or_npc( m_bad, _( "You throw up heavily!" ), _( "<npcname> throws up heavily!" ) );
7819 here.add_field( adjacent_tile(), fd_bile, 1 );
7820 } else {
7821 return;
7822 }
7823
7824 if( !has_effect( effect_nausea ) ) { // Prevents never-ending nausea
7825 const effect dummy_nausea( &effect_nausea.obj(), 0_turns, bodypart_str_id::NULL_ID(), 1,
7827 add_effect( effect_nausea, std::max( dummy_nausea.get_max_duration() *
7828 stomach.get_calories() / 100, dummy_nausea.get_int_dur_factor() ) );
7829 }
7830
7831 stomach.empty();
7832 set_thirst( std::max( 0, get_thirst() ) );
7834 if( get_healthy_mod() > 0 ) {
7835 set_healthy_mod( 0 );
7836 }
7837
7838 moves -= 100;
7839 // get_effect is more correct than has_effect because of body parts
7840 effect &eff_foodpoison = get_effect( effect_foodpoison );
7841 if( eff_foodpoison ) {
7842 eff_foodpoison.mod_duration( -30_minutes );
7843 }
7844 effect &eff_drunk = get_effect( effect_drunk );
7845 if( eff_drunk ) {
7846 eff_drunk.mod_duration( rng( -10_minutes, -50_minutes ) );
7847 }
7851 // Don't wake up when just retching
7852 wake_up();
7853}
static const efftype_id effect_fungus("fungus")
static const efftype_id effect_pkill2("pkill2")
static const efftype_id effect_bloated("bloated")
static const efftype_id effect_foodpoison("foodpoison")
static const efftype_id effect_pkill1("pkill1")
static const efftype_id effect_pkill3("pkill3")
tripoint adjacent_tile() const
Returns an unoccupied, safe adjacent point.
Definition: character.cpp:7856
void fungalize(const tripoint &p, Creature *origin=nullptr, double spore_chance=0.0)
field_type_id fd_bile
Definition: field_type.cpp:337

References _, Creature::add_effect(), Creature::add_msg_player_or_npc(), adjacent_tile(), effect_bloated, effect_drunk, effect_foodpoison, effect_fungus, effect_nausea, effect_pkill1, effect_pkill2, effect_pkill3, stomach_contents::empty(), fd_bile, fungal_effects::fungalize(), g, stomach_contents::get_calories(), Creature::get_effect(), Creature::get_effect_int(), get_healthy_mod(), effect::get_int_dur_factor(), get_map(), effect::get_max_duration(), get_thirst(), getID(), Creature::has_effect(), m_bad, effect::mod_duration(), Creature::moves, string_id< body_part_type >::NULL_ID(), string_id< T >::obj(), pos(), Creature::remove_effect(), rng(), set_healthy_mod(), set_thirst(), stomach, throws_up, calendar::turn, and wake_up().

Referenced by activate_mutation(), addict_effect(), iuse::artifact(), iuse::blech(), iuse::dig(), player::eat(), eff_fun_hallu(), eff_fun_hot(), eff_fun_rat(), player::hardcoded_effects(), marloss_common(), iuse::mycus(), player::process_effects_internal(), player::process_one_effect(), iuse::sewage(), suffer_from_radiation(), suffer_while_awake(), try_reject_mutagen(), avatar::vomit(), and spell_effect::vomit().

◆ wait_effects()

void Character::wait_effects ( )

Definition at line 1589 of file character.cpp.

1590{
1591 if( has_effect( effect_downed ) ) {
1592 try_remove_downed( *this );
1593 return;
1594 }
1595 if( has_effect( effect_beartrap ) ) {
1596 try_remove_bear_trap( *this );
1597 return;
1598 }
1599 if( has_effect( effect_lightsnare ) ) {
1600 try_remove_lightsnare( *this );
1601 return;
1602 }
1603 if( has_effect( effect_heavysnare ) ) {
1604 try_remove_heavysnare( *this );
1605 return;
1606 }
1607 if( has_effect( effect_webbed ) ) {
1608 try_remove_webs( *this );
1609 return;
1610 }
1611 if( has_effect( effect_grabbed ) ) {
1612 try_remove_grab( *this );
1613 return;
1614 }
1615}

References effect_beartrap, effect_downed, effect_grabbed, effect_heavysnare, effect_lightsnare, effect_webbed, Creature::has_effect(), try_remove_bear_trap(), try_remove_downed(), try_remove_grab(), try_remove_heavysnare(), try_remove_lightsnare(), and try_remove_webs().

◆ wake_up()

void Character::wake_up ( )

Removes "sleep" and "lying_down".

Definition at line 7687 of file character.cpp.

7688{
7692 if( has_effect( effect_sleep ) ) {
7693 g->events().send<event_type::character_wakes_up>( getID() );
7695 // Wake up might be called more than once per turn, but we only need to recalc after removing sleep
7697 }
7698}
static const efftype_id effect_slept_through_alarm("slept_through_alarm")
static const efftype_id effect_alarm_clock("alarm_clock")
@ character_wakes_up

References character_wakes_up, effect_alarm_clock, effect_lying_down, effect_sleep, effect_slept_through_alarm, g, getID(), Creature::has_effect(), recalc_sight_limits(), and Creature::remove_effect().

Referenced by player::hardcoded_effects(), on_hurt(), sounds::process_sound_markers(), react_to_felt_pain(), Creature::remove_effect(), suffer_from_asthma(), suffer_from_sunburn(), update_bodytemp(), vomit(), and avatar::wake_up().

◆ warmth()

std::map< bodypart_id, int > Character::warmth ( const std::map< bodypart_id, std::vector< const item * > > &  clothing_map) const

Returns warmth provided by armor, etc.

Definition at line 9386 of file character.cpp.

9388{
9389 std::map<bodypart_id, int> ret;
9390 for( const bodypart_id &bp : get_all_body_parts() ) {
9391 ret.emplace( bp, 0 );
9392 }
9393
9394 for( const std::pair<const bodypart_id, std::vector<const item *>> &on_bp : clothing_map ) {
9395 const bodypart_id &bp = on_bp.first;
9396 for( const item *it : on_bp.second ) {
9397 double warmth = it->get_warmth();
9398 // Warmth reduced linearly with wetness
9399 const auto &materials = it->made_of();
9400 float max_wet_resistance = std::accumulate( materials.begin(), materials.end(), 0.0f,
9401 []( float best, const material_id & mat ) {
9402 return std::max( best, mat->warmth_when_wet() );
9403 } );
9404 float wet_mult = 1.0f - max_wet_resistance * body_wetness[bp->token] / drench_capacity[bp->token];
9405 ret[bp] += warmth * wet_mult;
9406 }
9407 ret[bp] += get_effect_int( effect_heating_bionic, bp->token );
9408 }
9409 return ret;
9410}
static const efftype_id effect_heating_bionic("heating_bionic")
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5762

References body_wetness, drench_capacity, effect_heating_bionic, Creature::get_all_body_parts(), Creature::get_effect_int(), item::get_warmth(), item::made_of(), and cata::hash64_detail::ret.

Referenced by weather_effect::wet_player().

◆ wear_item()

cata::optional< std::list< item >::iterator > Character::wear_item ( const item to_wear,
bool  interactive = true 
)

Wear item; returns nullopt on fail, or pointer to newly worn item on success.

If interactive is false, don't alert the player or drain moves on completion.

Definition at line 2184 of file character.cpp.

2186{
2187 const auto ret = can_wear( to_wear );
2188 if( !ret.success() ) {
2189 if( interactive ) {
2190 add_msg_if_player( m_info, "%s", ret.c_str() );
2191 }
2192 return cata::nullopt;
2193 }
2194
2195 const bool was_deaf = is_deaf();
2196 const bool supertinymouse = get_size() == MS_TINY;
2197 last_item = to_wear.typeId();
2198
2199 std::list<item>::iterator position = position_to_wear_new_item( to_wear );
2200 std::list<item>::iterator new_item_it = worn.insert( position, to_wear );
2201
2202 if( interactive ) {
2204 _( "You put on your %s." ),
2205 _( "<npcname> puts on their %s." ),
2206 to_wear.tname() );
2207 moves -= item_wear_cost( to_wear );
2208
2209 for( const body_part bp : all_body_parts ) {
2210 if( to_wear.covers( bp ) && encumb( bp ) >= 40 ) {
2212 bp == bp_eyes ?
2213 _( "Your %s are very encumbered! %s" ) : _( "Your %s is very encumbered! %s" ),
2214 body_part_name( bp ), encumb_text( bp ) );
2215 }
2216 }
2217 if( !was_deaf && is_deaf() ) {
2218 add_msg_if_player( m_info, _( "You're deafened!" ) );
2219 }
2220 if( supertinymouse && !to_wear.has_flag( flag_UNDERSIZE ) ) {
2222 _( "This %s is too big to wear comfortably! Maybe it could be refitted." ),
2223 to_wear.tname() );
2224 } else if( !supertinymouse && to_wear.has_flag( flag_UNDERSIZE ) ) {
2226 _( "This %s is too small to wear comfortably! Maybe it could be refitted." ),
2227 to_wear.tname() );
2228 }
2229 } else {
2230 add_msg_if_npc( _( "<npcname> puts on their %s." ), to_wear.tname() );
2231 }
2232
2233 new_item_it->on_wear( *this );
2234
2235 inv.update_invlet( *new_item_it );
2236 inv.update_cache_with_item( *new_item_it );
2237
2240
2241 return new_item_it;
2242}
std::string encumb_text(body_part bp)
Returns the matching encumbrance text for a given body_part token.
Definition: bodypart.cpp:358
static const std::string flag_UNDERSIZE("UNDERSIZE")
void update_invlet(item &it, bool assign_invlet=true)
Definition: inventory.cpp:1214
void update_cache_with_item(item &newit)
Definition: inventory.cpp:252

References _, Creature::add_msg_if_npc(), Creature::add_msg_if_player(), Creature::add_msg_player_or_npc(), all_body_parts, body_part_name(), bp_eyes, can_wear(), item::covers(), encumb(), encumb_text(), flag_UNDERSIZE(), get_size(), item::has_flag(), inv, is_deaf(), item_wear_cost(), last_item, m_info, m_warning, Creature::moves, MS_TINY, cata::nullopt, position, position_to_wear_new_item(), recalc_sight_limits(), reset_encumbrance(), cata::hash64_detail::ret, item::tname(), item::typeId(), inventory::update_cache_with_item(), inventory::update_invlet(), and worn.

Referenced by activity_on_turn_wear(), iexamine::autodoc(), avatar::create(), dispose_item(), pick_one_up(), standard_npc::standard_npc(), npc::stow_item(), player::use(), player::wear(), and npc::wear_if_wanted().

◆ wearing_something_on()

bool Character::wearing_something_on ( const bodypart_id bp) const

Returns true if the character is wearing something on the entered body part.

Definition at line 8873 of file character.cpp.

8874{
8875 for( auto &i : worn ) {
8876 if( i.covers( bp->token ) ) {
8877 return true;
8878 }
8879 }
8880 return false;
8881}

References worn.

Referenced by armwear_factor(), can_drink_nectar(), can_wear(), iexamine::chainfence(), footwear_factor(), player::on_hit(), player::reset_stats(), suffer_from_sunburn(), and suffer_in_sunlight().

◆ weight_capacity()

units::mass Character::weight_capacity ( ) const
overridevirtual
Strength increases carrying capacity

Reimplemented from Creature.

Definition at line 2810 of file character.cpp.

2811{
2813 // Infinite enough
2814 return units::mass_max;
2815 }
2816 // Get base capacity from creature,
2817 // then apply player-only mutation and trait effects.
2819 /** @EFFECT_STR increases carrying capacity */
2820 ret += get_str() * 4_kilogram;
2821 ret *= mutation_value( "weight_capacity_modifier" );
2822
2823 units::mass worn_weight_bonus = 0_gram;
2824 for( const item &it : worn ) {
2825 ret *= it.get_weight_capacity_modifier();
2826 worn_weight_bonus += it.get_weight_capacity_bonus();
2827 }
2828
2829 units::mass bio_weight_bonus = 0_gram;
2830 for( const bionic_id &bid : get_bionics() ) {
2831 ret *= bid->weight_capacity_modifier;
2832 bio_weight_bonus += bid->weight_capacity_bonus;
2833 }
2834
2835 ret += bio_weight_bonus + worn_weight_bonus;
2836
2838 ret += 22500_gram;
2839 }
2840
2841 if( ret < 0_gram ) {
2842 ret = 0_gram;
2843 }
2844 if( is_mounted() ) {
2845 auto *mons = mounted_creature.get();
2846 // the mech has an effective strength for other purposes, like hitting.
2847 // but for lifting, its effective strength is even higher, due to its sturdy construction, leverage,
2848 // and being built entirely for that purpose with hydraulics etc.
2849 ret = mons->mech_str_addition() == 0 ? ret : ( mons->mech_str_addition() + 10 ) * 4_kilogram;
2850 }
2851 return ret;
2852}
virtual units::mass weight_capacity() const
Definition: creature.cpp:1774
@ AEP_CARRY_MORE
Definition: enums.h:118

References AEP_CARRY_MORE, get_bionics(), get_str(), has_artifact_with(), has_trait(), is_mounted(), units::mass_max, mounted_creature, mutation_value(), cata::hash64_detail::ret, trait_DEBUG_STORAGE, Creature::weight_capacity(), and worn.

Referenced by activate_bionic(), are_requirements_nearby(), burn_move_stamina(), can_pick_weight(), carry_weight_string(), pickup::cost_to_move_item(), overmap_ui::display(), pickup::do_pickup(), draw_speed_tab(), draw_stats_info(), draw_weightvolume_classic(), draw_weightvolume_compact(), draw_weightvolume_labels(), draw_weightvolume_narrow(), npc::drop_items(), fetch_activity(), find_best_bench(), npc::find_item(), inventory_selector::get_raw_stats(), inventory_drop_selector::get_raw_stats(), iexamine::ledge(), npc_pickup_from_stack(), trading_window::perform_trade(), player::recalc_speed_bonus(), set_stats(), suffer_while_awake(), and weight_carried_reduced_by().

◆ weight_carried()

◆ weight_carried_reduced_by()

units::mass Character::weight_carried_reduced_by ( const excluded_stacks without) const

Definition at line 2753 of file character.cpp.

2754{
2755 const std::map<const item *, int> empty;
2756
2757 // Worn items
2758 units::mass ret = 0_gram;
2759 for( auto &i : worn ) {
2760 if( !without.count( &i ) ) {
2761 ret += i.weight();
2762 }
2763 }
2764
2765 // Items in inventory
2766 ret += inv.weight_without( without );
2767
2768 // Wielded item
2769 units::mass weaponweight = 0_gram;
2770 auto weapon_it = without.find( &weapon );
2771 if( weapon_it == without.end() ) {
2772 weaponweight = weapon.weight();
2773 } else {
2774 int subtract_count = ( *weapon_it ).second;
2775 if( weapon.count_by_charges() ) {
2776 item copy = weapon;
2777 copy.charges -= subtract_count;
2778 if( copy.charges < 0 ) {
2779 debugmsg( "Trying to remove more charges than the wielded item has" );
2780 copy.charges = 0;
2781 }
2782 weaponweight = copy.weight();
2783 } else if( subtract_count > 1 ) {
2784 debugmsg( "Trying to remove more than one wielded item" );
2785 }
2786 }
2787 // Exclude wielded item if using lifting tool
2788 if( weaponweight + ret > weight_capacity() ) {
2789 const float liftrequirement = std::ceil( units::to_gram<float>( weaponweight ) /
2790 units::to_gram<float>( TOOL_LIFT_FACTOR ) );
2791 if( g->new_game || best_nearby_lifting_assist() < liftrequirement ) {
2792 ret += weaponweight;
2793 }
2794 } else {
2795 ret += weaponweight;
2796 }
2797
2798 return ret;
2799}
units::mass weight_without(const excluded_stacks &without) const
Definition: inventory.cpp:1039
#define TOOL_LIFT_FACTOR

References best_nearby_lifting_assist(), item::charges, item::count_by_charges(), debugmsg, g, inv, cata::hash64_detail::ret, TOOL_LIFT_FACTOR, weapon, item::weight(), weight_capacity(), inventory::weight_without(), and worn.

Referenced by inventory_drop_selector::get_raw_stats(), and weight_carried().

◆ wield()

virtual bool Character::wield ( item target)
pure virtual

Removes currently wielded item (if any) and replaces it with the target item.

Parameters
targetreplacement item to wield or null item to remove existing weapon without replacing it
Returns
whether both removal and replacement were successful (they are performed atomically)

Implemented in npc, and avatar.

Referenced by player::disarm(), handle_melee_wear(), mount_creature(), perform_technique(), pick_one_up(), and mattack::riotbot().

◆ will_eat()

ret_val< edible_rating > Character::will_eat ( const item food,
bool  interactive = false 
) const

Same as can_eat, but takes consequences into account.

Asks about them if

Parameters
interactiveis true, refuses otherwise.

Definition at line 729 of file consumption.cpp.

730{
731 const auto ret = can_eat( food );
732 if( !ret.success() ) {
733 if( interactive ) {
734 add_msg_if_player( m_info, "%s", ret.c_str() );
735 }
736 return ret;
737 }
738
739 std::vector<ret_val<edible_rating>> consequences;
740 const auto add_consequence = [&consequences]( const std::string & msg, edible_rating code ) {
741 consequences.emplace_back( ret_val<edible_rating>::make_failure( code, msg ) );
742 };
743
744 const bool saprophage = has_trait( trait_SAPROPHAGE );
745 const auto &comest = food.get_comestible();
746
747 if( food.rotten() ) {
748 const bool saprovore = has_trait( trait_SAPROVORE );
749 if( !saprophage && !saprovore && !has_bionic( bio_digestion ) ) {
750 add_consequence( _( "This is rotten and smells awful!" ), edible_rating::rotten );
751 }
752 }
753
754 const bool carnivore = has_trait( trait_CARNIVORE );
755 if( food.has_flag( flag_CANNIBALISM ) && !has_trait_flag( "CANNIBAL" ) ) {
756 add_consequence( _( "The thought of eating human flesh makes you feel sick." ),
758 }
759
760 const bool edible = comest->comesttype == comesttype_FOOD || food.has_flag( flag_USE_EAT_VERB );
761
762 int food_kcal = compute_effective_nutrients( food ).kcal;
763 if( food_kcal > 0 && has_effect( effect_nausea ) ) {
764 add_consequence( _( "You still feel nauseous and will probably puke it all up again." ),
766 }
767
768 if( ( food_kcal > 0 || comest->quench > 0 ) && has_effect( effect_bloated )
769 && !food.has_flag( flag_NO_BLOAT ) ) {
770 add_consequence( _( "You're full and will vomit if you try to consume anything." ),
772 }
773
774 if( ( allergy_type( food ) != MORALE_NULL ) || ( carnivore && food.has_flag( flag_ALLERGEN_JUNK ) &&
775 !food.has_flag( flag_CARNIVORE_OK ) ) ) {
776 add_consequence( _( "Your stomach won't be happy (allergy)." ), edible_rating::allergy );
777 }
778
779 if( saprophage && edible && food.rotten() && !food.has_flag( flag_FERTILIZER ) ) {
780 // Note: We're allowing all non-solid "food". This includes drugs
781 // Hard-coding fertilizer for now - should be a separate flag later
782 //~ No, we don't eat "rotten" food. We eat properly aged food, like a normal person.
783 //~ Semantic difference, but greatly facilitates people being proud of their character.
784 add_consequence( _( "Your stomach won't be happy (not rotten enough)." ),
786 }
787
788 if( !food.has_infinite_charges() &&
789 ( ( food_kcal > 0 &&
790 get_stored_kcal() + stomach.get_calories() + food_kcal
791 > max_stored_kcal() ) ||
792 ( comest->quench > 0 && get_thirst() < comest->quench ) ) ) {
793 add_consequence( _( "You're full already and the excess food will be wasted." ),
795 }
796
797 if( !consequences.empty() ) {
798 if( !interactive ) {
799 return consequences.front();
800 }
801 std::string req;
802 for( const auto &elem : consequences ) {
803 req += elem.str() + "\n";
804 }
805
806 const bool eat_verb = food.has_flag( flag_USE_EAT_VERB );
807 std::string food_tname = food.tname();
808 const nc_color food_color = food.color_in_inventory();
809 if( eat_verb || comest->comesttype == comesttype_FOOD ) {
810 req += string_format( _( "Eat your %s anyway?" ), colorize( food_tname, food_color ) );
811 } else if( !eat_verb && comest->comesttype == comesttype_DRINK ) {
812 req += string_format( _( "Drink your %s anyway?" ), colorize( food_tname, food_color ) );
813 } else {
814 req += string_format( _( "Consume your %s anyway?" ), colorize( food_tname, food_color ) );
815 }
816
817 if( !query_yn( req ) ) {
818 return consequences.front();
819 }
820 }
821 // All checks ended, it's edible (or we're pretending it is)
823}
edible_rating
Definition: character.h:156
bool has_infinite_charges() const
Definition: item.cpp:9782
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4015
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
static const std::string flag_FERTILIZER("FERTILIZER")
static const efftype_id effect_nausea("nausea")

References _, Creature::add_msg_if_player(), allergy, allergy_type(), allergy_weak, bio_digestion, bloated, can_eat(), cannibalism, item::color_in_inventory(), colorize(), comesttype_DRINK(), comesttype_FOOD(), compute_effective_nutrients(), edible, effect_bloated, effect_nausea, flag_ALLERGEN_JUNK(), flag_CANNIBALISM(), flag_CARNIVORE_OK(), flag_FERTILIZER(), flag_NO_BLOAT(), flag_USE_EAT_VERB(), stomach_contents::get_calories(), item::get_comestible(), get_stored_kcal(), get_thirst(), has_bionic(), Creature::has_effect(), item::has_flag(), item::has_infinite_charges(), has_trait(), has_trait_flag(), nutrients::kcal, m_info, ret_val< T >::make_success(), max_stored_kcal(), MORALE_NULL, nausea, query_yn(), cata::hash64_detail::ret, rotten, item::rotten(), stomach, string_format(), item::tname(), too_full, trait_CARNIVORE, trait_SAPROPHAGE, and trait_SAPROVORE.

Referenced by item::color_in_inventory(), npc::consume_food(), player::eat(), find_auto_consume(), rate_action_eat(), and npc::value().

◆ worn_position_to_index()

static int Character::worn_position_to_index ( int  position)
inlinestatic

Definition at line 1079 of file character.h.

1079 {
1080 return -2 - position;
1081 }

References position.

Referenced by advanced_inventory::action_examine(), get_item_position(), i_at(), i_rem(), and game::wield().

◆ worn_with_flag()

Member Data Documentation

◆ _skills

◆ activity

player_activity Character::activity

Definition at line 1524 of file character.h.

Referenced by activate_mutation(), activity_on_turn_move_loot(), assign_activity(), assign_stashed_activity(), iexamine::autodoc(), activity_handlers::build_do_turn(), iuse::burrow(), game::butcher(), butcher_corpse_activity(), player::calc_focus_equilibrium(), cancel_activity(), game::cancel_activity_or_ignore_query(), game::cancel_activity_query(), check_outbounds_activity(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), complete_construction(), player::complete_disassemble(), veh_interact::complete_vehicle(), construction_activity(), iuse::craft(), iuse::cut_log_into_planks(), player::disassemble(), player::disassemble_all(), npc::do_player_activity(), npc::do_pulp(), avatar::do_read(), game::do_turn(), player_activity::do_turn(), pickup_activity_actor::do_turn(), npc::drop(), eff_fun_bleed(), fall_asleep(), fetch_activity(), iuse::fill_pit(), activity_handlers::find_mount_do_turn(), npc::finish_read(), iuse::fishing_rod(), forced_dismount(), game::forced_door_closing(), generic_multi_activity_check_requirement(), generic_multi_activity_do(), generic_multi_activity_handler(), player_activity::get_progress_message(), talk_function::give_aid(), talk_function::give_all_aid(), player::gunmod_add(), iuse::hacksaw(), iuse::hand_crank(), game::handle_key_blocking_activity(), player::hardcoded_effects(), has_activity(), npc::has_player_activity(), in_sleep_state(), install_bionics(), inv_internal(), iuse::jackhammer(), load(), npc::load(), iuse::makemound(), mine_activity(), npc::move(), map::move_vehicle(), npc::on_load(), iuse::oxytorch(), perform_zone_activity_turn(), iuse::pickaxe(), game::place_player(), iuse::portable_game(), game::process_activity(), sounds::process_sound_markers(), player::process_turn(), game::process_voluntary_act_interrupt(), avatar::read(), npc::reboot(), game::reload(), DefaultRemovePartHandler::removed(), activity_handlers::repair_item_finish(), resume_backlog_activity(), npc::revert_after_activity(), iexamine::rubble(), iexamine::safe(), conditional_t< T >::set_has_activity(), npc::set_mission(), iexamine::shrub_wildveggies(), smash(), player::start_craft(), store(), player::toolmod_add(), try_start_hacking(), uninstall_bionic(), update_needs(), pick_lock_actor::use(), firestarter_actor::use(), enzlave_actor::use(), ammobelt_actor::use(), repair_item_actor::use(), heal_actor::use(), heal_actor::use_healing_item(), vehicle_activity(), and iuse::vibe().

◆ activity_vehicle_part_index

◆ addictions

◆ ammo_location

item_location Character::ammo_location

Definition at line 1549 of file character.h.

Referenced by player::load(), and player::store().

◆ auto_move_route

std::vector<tripoint> Character::auto_move_route
private

◆ backlog

◆ bio_soporific_powered_at_last_sleep_check

bool Character::bio_soporific_powered_at_last_sleep_check = false
protected

Definition at line 2080 of file character.h.

◆ blocks_left

int Character::blocks_left = 0

Definition at line 557 of file character.h.

Referenced by block_hit(), player::player(), and player::process_turn().

◆ body_wetness

◆ cached_crafting_inventory

inventory Character::cached_crafting_inventory
private

Definition at line 2203 of file character.h.

Referenced by crafting_inventory().

◆ cached_info

std::map<std::string, double> Character::cached_info
mutableprotected

◆ cached_moves

int Character::cached_moves = 0
private

Definition at line 2201 of file character.h.

Referenced by crafting_inventory().

◆ cached_mutations

std::vector<const mutation_branch *> Character::cached_mutations
protected

◆ cached_position

tripoint Character::cached_position
private

Definition at line 2202 of file character.h.

Referenced by crafting_inventory(), and invalidate_crafting_inventory().

◆ cached_time

time_point Character::cached_time

Definition at line 1552 of file character.h.

Referenced by crafting_inventory(), and invalidate_crafting_inventory().

◆ camps

std::set<tripoint_abs_omt> Character::camps

◆ cash

int Character::cash = 0

◆ check_encumbrance

bool Character::check_encumbrance = true
private

◆ consumption_history

pimpl<consumption_history_t> Character::consumption_history

Definition at line 1536 of file character.h.

Referenced by player::eat(), fun_for(), load(), and store().

◆ controlling_vehicle

◆ custom_profession

std::string Character::custom_profession

◆ damage_bandaged

std::array<int, num_hp_parts> Character::damage_bandaged

Definition at line 1516 of file character.h.

Referenced by heal_actor::finish_using(), load(), regen(), and player::store().

◆ damage_disinfected

std::array<int, num_hp_parts> Character::damage_disinfected

Definition at line 1516 of file character.h.

Referenced by iexamine::autodoc(), heal_actor::finish_using(), load(), regen(), and player::store().

◆ death_drops

bool Character::death_drops = true

Definition at line 225 of file character.h.

Referenced by npc::npc(), place_corpse(), and player::player().

◆ destination_activity

player_activity Character::destination_activity
private

◆ destination_point

◆ dex_bonus

int Character::dex_bonus = 0
protected

◆ dex_cur

◆ dex_max

◆ dodges_left

int Character::dodges_left = 0

◆ drench_capacity

std::array<int, num_bp> Character::drench_capacity

◆ enchantment_cache

◆ encumbrance_cache

pimpl<char_encumbrance_data> Character::encumbrance_cache
protected

Definition at line 2078 of file character.h.

Referenced by encumb(), extraEncumbrance(), get_encumbrance(), and reset_encumbrance().

◆ fac_id

◆ faction_api_version

int Character::faction_api_version = 2
protected

◆ fatigue

int Character::fatigue = 0
private

◆ fleshy

const std::vector< material_id > Character::fleshy = { material_id( "flesh" ), material_id( "hflesh" ) }
static

Definition at line 770 of file character.h.

Referenced by made_of(), and made_of_any().

◆ focus_pool

◆ follower_ids

std::set<character_id> Character::follower_ids

Definition at line 1545 of file character.h.

Referenced by player::load(), and player::store().

◆ frostbite_timer

std::array<int, num_bp> Character::frostbite_timer

Definition at line 2215 of file character.h.

Referenced by load(), store(), and update_bodytemp().

◆ hauling

bool Character::hauling = false

Definition at line 1520 of file character.h.

Referenced by is_hauling(), player::player(), start_hauling(), and stop_hauling().

◆ healed_total

std::array<int, num_hp_parts> Character::healed_total

Definition at line 1727 of file character.h.

Referenced by healed_bp(), load(), and store().

◆ healthy

int Character::healthy = 0
protected

How healthy the character is.

Definition at line 2067 of file character.h.

Referenced by get_healthy(), load(), mod_healthy(), set_healthy(), and store().

◆ healthy_mod

int Character::healthy_mod = 0
protected

Definition at line 2068 of file character.h.

Referenced by get_healthy_mod(), load(), mod_healthy_mod(), set_healthy_mod(), and store().

◆ id

◆ in_vehicle

◆ init_age

int Character::init_age = 25
protected

age in years at character creation

Definition at line 2071 of file character.h.

Referenced by age(), base_age(), load(), mod_base_age(), avatar::randomize(), reset_chargen_attributes(), set_base_age(), and store().

◆ init_height

int Character::init_height = 175
protected

height at character creation

Definition at line 2073 of file character.h.

Referenced by base_height(), height(), load(), mod_base_height(), avatar::randomize(), reset_chargen_attributes(), set_base_height(), and store().

◆ int_bonus

int Character::int_bonus = 0
protected

◆ int_cur

◆ int_max

◆ inv

inventory Character::inv

Definition at line 1527 of file character.h.

Referenced by inventory_selector::add_character_items(), advanced_inventory_pane::add_items_from_area(), allocated_invlets(), npc::alt_attack(), autoclave_internal(), autodoc_internal(), player::can_disassemble(), behavior::character_oracle_t::can_make_fire(), can_pick_volume(), player::can_start_craft(), iuse_transform::can_use(), behavior::character_oracle_t::can_wear_warmer_clothes(), debug_menu::character_edit_menu(), game_menus::inv::common(), game_menus::inv::compare(), complete_craft(), player::consume(), npc::consume_cbm_items(), npc::consume_food(), convert_to_items(), crafting_inventory(), avatar::create(), npc::decide_needs(), die(), dispose_item(), npc::dispose_item(), drop_invalid_inventory(), npc::drop_items(), findBestGasDiscount(), player::get_artifact_items(), player::get_eligible_containers_for_crafting(), item::get_encumber(), get_item_position(), item::get_remaining_capacity_for_liquid(), get_weight(), behavior::character_oracle_t::has_food(), npc::has_painkiller(), behavior::character_oracle_t::has_water(), npc::heal_self(), i_add(), i_add_or_drop(), i_at(), i_rem(), tutorial_game::init(), npc_trading::init_buying(), npc_trading::init_selling(), inv_dump(), inv_internal(), irradiate(), leak_level(), avatar::load(), load(), monster::load(), player::mend_item(), npc::mug_player(), game_menus::inv::multidrop(), iexamine::pay_gas(), pour_into(), player::process_items(), iuse::radiocar(), npc::randomize(), player::reassign_item(), item::reload(), pickup::reorder_for_dropping(), player::select_requirements(), set_item_inventory(), npc::shop_restock(), iuse::smoking(), player::sort_armor(), starting_inv(), avatar::store(), monster::store(), player::store(), game_menus::inv::swap_letters(), avatar_action::swim(), player::takeoff(), player::unwield(), npc::update_worst_item_value(), use_amount(), npc::use_painkiller(), volume_carried(), volume_carried_reduced_by(), wash_items(), player::wear(), wear_item(), weight_carried_reduced_by(), npc::wield(), avatar::wield(), npc::wield_better_weapon(), player::wield_contents(), and memorial_logger::write().

◆ known_traps

trap_map Character::known_traps
protected

Definition at line 2077 of file character.h.

Referenced by add_known_trap(), knows_trap(), load(), and store().

◆ last_climate_control_ret

bool Character::last_climate_control_ret = false

Definition at line 2220 of file character.h.

Referenced by in_climate_control(), and game::start_game().

◆ last_item

◆ last_sleep_check

time_point Character::last_sleep_check = calendar::turn_zero
protected

last time we checked for sleep

Definition at line 2082 of file character.h.

Referenced by player::load(), and player::store().

◆ last_target

weak_ptr_fast<Creature> Character::last_target

Definition at line 1546 of file character.h.

Referenced by player::load(), and player::store().

◆ last_target_pos

cata::optional<tripoint> Character::last_target_pos

Definition at line 1547 of file character.h.

Referenced by player::load(), and player::store().

◆ magic

◆ male

◆ martial_arts_data

◆ max_power_level

◆ melee_miss_reasons

struct weighted_int_list< std::string > Character::melee_miss_reasons
private

Definition at line 2199 of file character.h.

Referenced by add_miss_reason(), clear_miss_reasons(), and get_miss_reason().

◆ morale

◆ mounted_creature

◆ mounted_creature_id

int Character::mounted_creature_id = 0

Definition at line 1566 of file character.h.

Referenced by load().

◆ move_mode

◆ mut_drench

std::array<std::array<int, NUM_WATER_TOLERANCE>, num_bp> Character::mut_drench
protected

Definition at line 844 of file character.h.

Referenced by apply_wetness_morale(), and drench_mut_calc().

◆ mutation_category_level

std::map<std::string, int> Character::mutation_category_level

◆ my_bionics

◆ my_fac

◆ my_mutations

std::unordered_map<trait_id, trait_data> Character::my_mutations
protected

Traits / mutations of the character.

Key is the mutation id (it's also a valid key into mutation_data), the value describes the status of the mutation. If there is not entry for a mutation, the character does not have it. If the map contains the entry, the character has the mutation.

Definition at line 2091 of file character.h.

Referenced by activate_mutation(), active_light(), clear_mutations(), avatar::create(), deactivate_mutation(), get_mutations(), get_overlay_ids(), has_active_mutation(), has_opposite_trait(), has_trait(), load(), mutation_effect(), mutation_spend_resources(), player::power_mutations_ui(), rebuild_mutation_cache(), set_mutation(), store(), suffer(), switch_mutations(), toggle_trait(), trait_by_invlet(), and unset_mutation().

◆ my_traits

std::unordered_set<trait_id> Character::my_traits
protected

Contains mutation ids of the base traits.

Definition at line 2095 of file character.h.

Referenced by clear_mutations(), get_base_traits(), has_base_trait(), load(), store(), and toggle_trait().

◆ name

std::string Character::name

Definition at line 1512 of file character.h.

Referenced by assign_activity(), vehicle::automatic_fire_turret(), bionics_install_failure(), map::board_vehicle(), body_window(), butcher_corpse_activity(), butchery_drops_harvest(), talk_function::buy_100_logs(), talk_function::buy_10_logs(), talk_function::buy_haircut(), talk_function::buy_shave(), veh_interact::calc_overview(), can_wear(), enchantment::cast_enchantment_spell(), debug_menu::character_edit_menu(), activity_handlers::chop_logs_finish(), game::cleanup_at_end(), veh_interact::complete_vehicle(), target_ui::confirm_non_enemy_target(), npc::consume_food(), player::consume_item(), avatar::create(), mission_end::deposit_box(), item_location::impl::item_on_person::describe(), basecamp::deserialize(), faction::deserialize(), vehicle::deserialize(), npc::die(), player::disarm(), disp_name(), npc::do_reload(), overmap_ui::draw_ascii(), draw_tip(), npc::drop_items(), dialogue::dynamic_line(), talk_function::end_conversation(), enumerate_unmet_requirements(), npc::execute_action(), extended_description(), npc::faction_display(), fetch_activity(), talk_function::field_build_1(), talk_function::field_build_2(), talk_function::field_plant(), basecamp::finish_return(), player::fire_gun(), overmapbuffer::fix_npcs(), talk_function::flee(), talk_function::forage_return(), game::forced_door_closing(), npc::form_opinion(), iuse::geiger(), generic_multi_activity_locations(), get_name(), game::get_player_base_save_path(), vehicle::get_targeting_npc(), talk_function::give_aid(), talk_function::give_all_aid(), talk_function::give_equipment(), npc::go_to_omt_destination(), npc::handle_sound(), player::hardcoded_effects(), iexamine::harvest_plant(), healing_rate(), talk_function::hostile(), talk_function::insult_combat(), activity_handlers::jackhammer_finish(), talk_function::labor_return(), talk_function::leave(), load(), npc::load(), npc_template::load(), game::load(), submap::load(), npc::load_npc_template(), make_fake_npc(), melee_attack(), talk_function::morale_chat_activity(), npc::move(), move_item(), game::move_save_to_graveyard(), npc::move_to(), npc::mug_player(), mutation_attacks(), game::npc_menu(), npc_temp_orders_menu(), npc_throw(), player::on_hit(), npc::on_load(), dialogue::opt(), perform_technique(), trading_window::perform_trade(), petfood(), pick_name(), npc::pick_up_item(), activity_handlers::pickaxe_finish(), place_corpse(), mission_start::place_dog(), mission_start::place_npc_software(), npc::print_info(), print_info(), game::quickload(), avatar::randomize(), talk_function::remove_overseer(), reveal_target(), rod_fish(), game::save(), avatar::save_template(), npc::say(), npc::scan_new_items(), talk_function::scavenging_patrol_return(), talk_function::scavenging_raid_return(), player::select_ammo(), basecamp::serialize(), faction::serialize(), vehicle::serialize(), npc::set_attitude(), set_description(), talk_function::set_npc_pickup(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_buy_monster(), talk_effect_fun_t::set_u_sell_item(), npc::setpos(), short_description_parts(), show_photo_selection(), player::sort_armor(), standard_npc::standard_npc(), talk_function::start_mugging(), game_menus::inv::steal(), avatar::steal(), talk_function::stop_following(), talk_function::stop_guard(), npc::store(), talk_function::stranger_neutral(), suffer_from_schizophrenia(), survive_random_encounter(), npc::talk_to_u(), tidy_activity(), npc::travel_overmap(), update_time_fixed(), trading_window::update_win(), npc::warn_about(), and memorial_logger::write().

◆ next_climate_control_check

time_point Character::next_climate_control_check

Definition at line 2219 of file character.h.

Referenced by in_climate_control(), and game::start_game().

◆ next_expected_position

cata::optional<tripoint> Character::next_expected_position
private

◆ nv_cached

bool Character::nv_cached = false

Definition at line 1517 of file character.h.

Referenced by action_taken(), has_nv(), player::player(), and reset_stats().

◆ nv_range

float Character::nv_range = 0
protected

Definition at line 2110 of file character.h.

Referenced by get_vision_threshold(), and recalc_sight_limits().

◆ omt_path

◆ overmap_time

std::unordered_map<point_abs_omt, time_duration> Character::overmap_time
protected

Amount of time the player has spent in each overmap tile.

Definition at line 2211 of file character.h.

Referenced by apply_persistent_morale(), load(), player::process_turn(), and store().

◆ oxygen

◆ path_settings

pimpl<pathfinding_settings> Character::path_settings
mutableprotected

Cache for pathfinding settings.

Most of it isn't changed too often, hence mutable.

Definition at line 2121 of file character.h.

Referenced by get_pathfinding_settings(), npc::get_pathfinding_settings(), avatar::grab(), and npc::npc().

◆ per_bonus

int Character::per_bonus = 0
protected

◆ per_cur

◆ per_max

◆ pkill

int Character::pkill = 0
private

◆ position

◆ power_level

units::energy Character::power_level
private

◆ prof

◆ radiation

int Character::radiation = 0
private

Definition at line 2192 of file character.h.

Referenced by get_rad(), load(), set_rad(), and store().

◆ reach_attacking

bool Character::reach_attacking = false

Definition at line 601 of file character.h.

Referenced by melee_attack(), and player::reach_attack().

◆ reactor_plut

int Character::reactor_plut = 0

Definition at line 1540 of file character.h.

Referenced by activate_bionic(), player::load(), player::store(), and suffer_from_radiation().

◆ recoil

◆ scent

int Character::scent = 0

Definition at line 1531 of file character.h.

Referenced by player::load(), and player::store().

◆ sight_max

int Character::sight_max = 0
protected

Definition at line 2111 of file character.h.

Referenced by player::player(), recalc_sight_limits(), sight_range(), and unimpaired_range().

◆ size_class

m_size Character::size_class = MS_MEDIUM
protected

Size class of character.

Definition at line 2075 of file character.h.

Referenced by get_size(), and recalculate_size().

◆ sleep_deprivation

int Character::sleep_deprivation = 0
private

◆ slow_rad

int Character::slow_rad = 0

Definition at line 1541 of file character.h.

Referenced by activate_bionic(), player::load(), player::store(), and suffer_from_radiation().

◆ stamina

int Character::stamina = 0
private

Definition at line 2183 of file character.h.

Referenced by get_stamina(), load(), mod_stamina(), set_stamina(), and store().

◆ stashed_outbounds_activity

◆ stashed_outbounds_backlog

player_activity Character::stashed_outbounds_backlog

◆ stim

int Character::stim = 0
private

Definition at line 2189 of file character.h.

Referenced by get_stim(), load(), mod_stim(), set_stim(), and store().

◆ stomach

◆ stored_calories

int Character::stored_calories = 0
private

Needs (hunger, starvation, thirst, fatigue, etc.)

Definition at line 2180 of file character.h.

Referenced by get_hunger_description(), get_stored_kcal(), load(), mod_stored_kcal(), set_stored_kcal(), and store().

◆ str_bonus

int Character::str_bonus = 0
protected

Bonuses to stats, calculated each turn.

Definition at line 2061 of file character.h.

Referenced by get_str(), get_str_bonus(), load(), mod_str_bonus(), reset_bonuses(), set_str_bonus(), and store().

◆ str_cur

◆ str_max

◆ tank_plut

int Character::tank_plut = 0

◆ temp_conv

◆ temp_cur

◆ thirst

int Character::thirst = 0
private

Definition at line 2182 of file character.h.

Referenced by get_thirst(), get_thirst_description(), load(), mod_thirst(), set_thirst(), and store().

◆ time_died

time_point Character::time_died = calendar::before_time_starts
protected

Definition at line 2115 of file character.h.

Referenced by get_time_died(), and set_time_died().

◆ type_of_scent

scenttype_id Character::type_of_scent
private

Definition at line 2197 of file character.h.

Referenced by get_type_of_scent(), load(), set_type_of_scent(), and store().

◆ vision_mode_cache

std::bitset<NUM_VISION_MODES> Character::vision_mode_cache
protected

◆ vitamin_levels

std::map<vitamin_id, int> Character::vitamin_levels
protected

Current deficiency/excess quantity for each vitamin.

Definition at line 2134 of file character.h.

Referenced by load(), player::player(), store(), vitamin_get(), vitamin_mod(), and vitamin_set().

◆ warning_record

std::map<faction_id, std::pair<int, time_point> > Character::warning_record
protected

warnings from a faction about bad behavior

Definition at line 2084 of file character.h.

Referenced by player::load(), and player::store().

◆ weapon

item Character::weapon

Definition at line 1529 of file character.h.

Referenced by activate_bionic(), inventory_selector::add_character_items(), npc::aim(), allocated_invlets(), npc::alt_attack(), apply_damage(), avatar_action::autoattack(), npc::average_damage_dealt(), best_shield(), mattack::bio_op_disarm(), mattack::bio_op_takedown(), block_hit(), can_fire_turret(), avatar_action::can_fire_weapon(), npc::can_reload_current(), can_wear(), player::can_wield(), cast_spell(), npc::character_danger(), debug_menu::character_edit_menu(), check_art_charge_req(), npc::check_or_use_weapon_cbm(), player::consume(), mattack::copbot(), crafting_inventory(), avatar::create(), deactivate_bionic(), deal_damage(), npc::decide_needs(), player::disarm(), npc::discharge_cbm_weapon(), dismount(), iuse::ehandcuffs(), explosion_handler::emp_blast(), empty_buckets(), npc::execute_action(), extended_description(), npc::faction_display(), fire(), player::fire_gun(), avatar_action::fire_wielded_weapon(), forced_dismount(), npc::form_opinion(), mattack::frag(), player::get_artifact_items(), player::get_eligible_containers_for_crafting(), get_item_position(), get_overlay_ids(), item::get_remaining_capacity_for_liquid(), aim_activity_actor::get_weapon(), get_weight(), give_item_to(), mattack::grab(), player::gun_value(), game::handle_action(), handle_problematic_pickup(), player::hardcoded_effects(), hardcoded_mutation_attack(), has_artifact_with(), i_at(), i_rem(), npc_trading::init_buying(), npc_trading::init_selling(), player::intimidation(), inv_dump(), npc::invalidate_range_cache(), game::inventory_item_menu(), is_armed(), steal_inventory_preset::is_shown(), ma_requirements::is_valid_character(), is_wielding(), item_handling_cost(), mdeath::jabberwock(), game::list_monsters(), load(), game::load(), character_martial_arts::martialart_use_message(), melee_attack(), melee_special_effects(), player::melee_value(), avatar_action::mend(), npc::method_of_attack(), npc::move(), avatar_action::move(), npc::move_pause(), npc::move_to(), normalize(), npc::npc_dismount(), item_location::impl::item_on_person::obtain_cost(), player::on_dodge(), parse_tags(), pick_one_up(), avatar_action::plthrow(), power_rating(), npc::pretend_fire(), print_aim(), npc::print_info(), game::process_artifact(), item::process_extinguish(), player::process_items(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), npc::randomize(), rate_critter(), reach_attack(), player::reach_attack(), npc::regen_ai_cache(), game::reload_wielded(), remove_weapon(), mattack::rifle(), mattack::riotbot(), character_martial_arts::selected_style_name(), conditional_t< T >::set_can_stow_weapon(), gun_actor::shoot(), short_description_parts(), smash(), npc::smash_ability(), starting_inv(), npc::starting_weapon(), player::store(), npc::stow_item(), suffer_from_bad_bionics(), suffer_from_schizophrenia(), suffer_from_sunburn(), mattack::tankgun(), game::try_get_right_click_action(), salvage_actor::try_to_cut_up(), player::unwield(), update_bodytemp(), trading_window::update_win(), use_amount(), used_weapon(), npc::value(), player::weapname(), player::wear(), weight_carried_reduced_by(), weather_effect::wet_player(), npc::wield(), avatar::wield(), npc::wield_better_weapon(), player::wield_contents(), and memorial_logger::write().

◆ worn

std::list<item> Character::worn

Definition at line 1515 of file character.h.

Referenced by absorb_hit(), active_light(), advanced_inventory_pane::add_items_from_area(), npc::adjust_worn(), allocated_invlets(), amount_worn(), best_shield(), bodypart_exposure(), can_swap(), player::can_takeoff(), can_wear(), debug_menu::character_edit_menu(), check_and_recover_morale(), check_art_charge_req(), check_item_encumbrance_flag(), player::consume(), covered_with_flag(), crafting_inventory(), deal_damage(), dispose_item(), npc::dispose_item(), exclusive_flag_coverage(), extended_description(), fire(), get_armor(), get_armor_bash_base(), get_armor_bullet_base(), get_armor_cut_base(), get_armor_type(), player::get_artifact_items(), get_dependent_worn_items(), get_effective_efficiency(), player::get_eligible_containers_for_crafting(), item::get_encumber(), get_env_resist(), get_item_position(), get_overlay_ids(), get_weight(), player::hardcoded_effects(), has_artifact_with(), head_cloth_encumbrance(), i_at(), i_rem(), player::immune_to(), in_climate_control(), inv_dump(), is_wearing(), is_wearing_active_optcloak(), is_wearing_active_power_armor(), is_wearing_helmet(), is_wearing_on_bp(), is_wearing_power_armor(), is_wearing_shoes(), is_worn(), item_encumb(), item_worn_with_flag(), load(), natural_attack_restricted_on(), item::on_wear(), map::player_in_field(), position_to_wear_new_item(), npc::print_info(), player::process_items(), item::process_tool(), remove_worn_items_with(), short_description_parts(), player::sort_armor(), standard_npc::standard_npc(), starting_clothes(), player::store(), npc::stow_item(), swim_speed(), player::takeoff(), update_bodytemp(), set_transform_iuse::use(), use_amount(), volume_capacity_reduced_by(), npc::wear_if_wanted(), wear_item(), wearing_something_on(), weight_capacity(), weight_carried_reduced_by(), weather_effect::wet_player(), avatar::wield(), game::wield(), worn_with_flag(), and memorial_logger::write().


The documentation for this class was generated from the following files: